search

package
v0.0.0-...-ba2758a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

Similarity search between word vectors.

Usage

Search similar words

Usage:
  wego search [flags]

Examples:
  wego search -i example/word_vectors.txt microsoft

Flags:
  -h, --help               help for search
  -i, --inputFile string   input file path for trained word vector (default "example/input.txt")
  -r, --rank int           how many the most similar words will be displayed (default 10)

Example

$ go run wego.go search -i example/word_vectors_sg.txt microsoft
  RANK |    WORD    | SIMILARITY
+------+------------+------------+
     1 | apple      |   0.994008
     2 | operating  |   0.992855
     3 | versions   |   0.992800
     4 | ibm        |   0.992232
     5 | os         |   0.989174
     6 | computers  |   0.988998
     7 | machines   |   0.988804
     8 | dvd        |   0.988732
     9 | cd         |   0.988259
    10 | compatible |   0.988200

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Describe

func Describe(neighbors Neighbors) error

Describe shows the similar words list for target word.

func ParseAll

func ParseAll(f io.Reader, store StoreFunc) error

Types

type Neighbor

type Neighbor struct {
	// contains filtered or unexported fields
}

Neighbor stores the word with cosine similarity value on the target.

type Neighbors

type Neighbors []Neighbor

Neighbors is the list of Sim.

func (Neighbors) Len

func (n Neighbors) Len() int

func (Neighbors) Less

func (n Neighbors) Less(i, j int) bool

func (Neighbors) Swap

func (n Neighbors) Swap(i, j int)

type Searcher

type Searcher struct {
	Vectors   map[string][]float64
	Dimension int
}

Searcher stores the elements for cosine similarity.

func NewSearcher

func NewSearcher(f io.Reader) (*Searcher, error)

NewSearcher creates *Searcher

func (*Searcher) Search

func (s *Searcher) Search(queryVec []float64, k int) (Neighbors, error)

func (*Searcher) SearchWithQuery

func (s *Searcher) SearchWithQuery(query string, k int) (Neighbors, error)

Search searches similar words for query word and returns top-k nearest neighbors with similarity.

type StoreFunc

type StoreFunc func(string, []float64, int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL