vector

package
v0.0.0-...-de70c8a Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package vector implements word vector struct of word2vec.

Example (Dot)
v := New(strings.Split("1.0 0.0 0.0 1.0 0.0 1.0 ", " "))
u := New(strings.Split(" 0.0 1.0 0.0 0.0 1.0 1.0", " "))
fmt.Println(v.dot(u))
Output:

1
Example (Norm)
v := New(strings.Split("1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ", " "))
fmt.Println(v.norm())
Output:

2.8284271247461903

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cos

func Cos(v, u Vector) float64

Cos computes the cosine similarity of the given vectors.

Example
v := New(strings.Split("1.0 0.0 0.0 1.0 0.0 1.0 ", " "))
u := New(strings.Split(" 0.0 1.0 0.0 0.0 1.0 1.0", " "))
fmt.Println(Cos(v, u))
Output:

0.33333333333333337

func Train

func Train(data, output string) error

Train trains word vectors using wego APIs.

Types

type Expr

type Expr struct {
	Sentence   string
	Similarity float64
}

Expr is an expression type.

Example
v := New(strings.Split("1.0 0.0 0.0 1.0 0.0 1.0 ", " "))
u := New(strings.Split(" 0.0 1.0 0.0 0.0 1.0 1.0", " "))
s := "king"
expr := NewExpr(v, u, s)
fmt.Println(expr)
Output:

king	0.333333%

func NewExpr

func NewExpr(v, u Vector, sentence string) Expr

NewExpr returns a new Expr.

func (Expr) String

func (e Expr) String() string

String implements fmt.Stringer interface.

type Vector

type Vector []float64

Vector is a type which represents a word vector.

func New

func New(data []string) Vector

New returns a new vector with a given data.

Example
data := strings.Split("1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ", " ")
v := New(data)
fmt.Println(v)
Output:

Vector(1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000)
L2 Norm: 2.828427

func Word2Sent

func Word2Sent(vectors []Vector) Vector

Word2Sent returns the average vector of the given vectors.

func (Vector) String

func (v Vector) String() (str string)

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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