• Stars
    star
    184
  • Rank 203,640 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go library for performing computations in word2vec binary models

word2vec

Build Status GoDoc

word2vec is a Go package which provides functions for querying word2vec models (see https://code.google.com/p/word2vec). Any binary word2vec model file can be loaded and queried.

Requirements

Installation

If you haven't setup Go before, you need to first set a GOPATH (see https://golang.org/doc/code.html#GOPATH).

To fetch and build the code:

$ go get code.sajari.com/word2vec/...

This will build the command line tools (in particular word-calc, word-server, word-client) into $GOPATH/bin (assumed to be in your PATH already).

Usage

word-calc

The word-calc tool is a quick way to perform basic word calculations on a word2vec model. For instance: vec(king) - vec(man) + vec(woman) would be equivalent to:

$ word-calc -model /path/to/model.bin -add king,woman -sub man

See word-calc -h for full more details. Note that word-calc first loads the model every time, and so can appear to be quite slow. Use word-server and word-client to get better performance when running multiple queries on the same model.

word-server and word-client

The word-server tool (see cmd/word-server) creates an HTTP server which wraps a word2vec model which can be queried from Go using a Client, or using the word-client tool (see cmd/word-client).

$ word-server -model /path/to/model.bin -listen localhost:1234

A simple code example using Client:

c := word2vec.Client{Addr: "localhost:1234"}

// Create an expression.
expr := word2vec.Expr{}
expr.Add(1, "king")
expr.Add(-1, "man")
expr.Add(1, "woman")

// Find the most similar result by cosine similarity.
matches, err := c.CosN(expr, 1)
if err != nil {
	log.Fatalf("error evaluating cosine similarity: %v", err)
}

API Example

Alternatively you can interact with a word2vec model directly in your code:

// Load the model from an io.Reader (i.e. a file).
model, err := word2vec.FromReader(r)
if err != nil {
	log.Fatalf("error loading model: %v", err)
}

// Create an expression.
expr := word2vec.Expr{}
expr.Add(1, "king")
expr.Add(-1, "man")
expr.Add(1, "woman")

// Find the most similar result by cosine similarity.
matches, err := model.CosN(expr, 1)
if err != nil {
	log.Fatalf("error evaluating cosine similarity: %v", err)
}

More Repositories

1

docconv

Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text
Go
1,370
star
2

regression

Multivariable regression library in Go
Go
384
star
3

fuzzy

Spell checking and fuzzy search suggestion written in Go
Go
367
star
4

storage

Go package for abstracting local, in-memory, and remote (Google Cloud Storage/S3) filesystems
Go
52
star
5

sdk-react

Official repository of the Search.io SDK for React
TypeScript
40
star
6

fastentity

Fast identification of character sequences in text or documents (multi-lingual)
Go
18
star
7

simple-linkedin-php

A fork of http://code.google.com/p/simple-linkedinphp/
PHP
10
star
8

sdk-node

Official repository of the Search.io SDK for Node.js
TypeScript
8
star
9

sdk-js

Official repository of the Search.io SDK for JavaScript integration into web applications
TypeScript
8
star
10

sdk-php

Official repository of the Search.io SDK for PHP
PHP
8
star
11

sajari-sdk-go

Search.io APIs Go Client Library
Go
4
star
12

sdk-react-guide

Examples and guides to get started with the Search.io React SDK
JavaScript
4
star
13

sdk-dotnet

Official repository of the Search.io SDK for .NET
C#
4
star
14

env

Environment variable management for services
Go
4
star
15

sdk-go

Official repository of the Search.io SDK for Go
Go
3
star
16

mlg

Generates code to a) train ML models in various languages and b) predict directly in Go
Smarty
3
star
17

community

Join to exchange ideas, ask questions, or make suggestions on how we can improve Search.io.
3
star
18

proto

Protocol Buffer Definitions for Search.io gRPC APIs
3
star
19

sdk_ruby

Official repository of the Search.io SDK for Ruby
Ruby
3
star
20

talks

Sajari presentations
Go
3
star
21

gommap

Go
2
star
22

setup-cue

Setup cuelang in your GitHub Actions workflow
2
star
23

node-sdk-scripts

A set of modules to assist with uploading data to Search.io
JavaScript
1
star
24

protogen-go

Generated Go packages for Search.io gRPC APIs
Shell
1
star
25

website-search-integration

Search.io Website Search Integration
TypeScript
1
star
26

sdk-python

Official repository of the Search.io SDK for Python
Python
1
star
27

client-sajari-service

Java
1
star