Coder Social home page Coder Social logo

pyemblib's Introduction

pyemblib

A module for reading, writing, and using trained word embeddings.

Installation

Install with pip!

pip install pyemblib

Usage

This package currently supports word embeddings trained by the following packages:

Reading

Both text-format and binary embedding files are supported.

The example below shows reading each format of embedding:

## import text embeddings
text_embs = pyemblib.read('/tmp/text_embeddings.txt', mode=pyemblib.Mode.Text)
## import binary embeddings
bin_embs = pyemblib.read('/tmp/bin_embeddings.bin', mode=pyemblib.Mode.Binary)

Embeddings are read as a pyemblib.Embeddings object, which inherits from Python's dictionary class; keys are words, and values are the embedding arrays.

To get the word vector for "python", just use dictionary access:

vec = embs['python']
print(vec)
# [ 0.001 -0.237 ... ]

Writing

The same text and binary modes can be used for writing out embedding files as for reading.

embs = { 'a' : np.array([0.3 0.1 -0.2]), 'b' : np.array([-0.9, -0.2, -0.2]) }
## write as text
pyemblib.write(embs, '/tmp/text_embeddings.txt', mode=pyemblib.Mode.Text)
## write as binary
pyemblib.write(embs, '/tmp/bin_embeddings.bin', mode=pyemblib.Mode.Binary)

Feedback

Please report any issues you encounter to the Github Issues page!

pyemblib's People

Contributors

drgriffis avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ahaldar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.