-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedding_base.py
63 lines (46 loc) · 1.44 KB
/
embedding_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
each new embedding method (like word2vec or fastText) must inherit from
the class EmbeddingBaseAbstract and implement all its functions
"""
from abc import ABC, abstractmethod
class EmbeddingAbstractBase(ABC):
@abstractmethod
def __init__(self, config):
# initialize object variables like self._model
pass
@abstractmethod
def train_model(self, train_data_src, emb_model_dir, emb_model_fn):
# train a model and store it in embeddig object
pass
@abstractmethod
def similarity(self, word1, word2):
# return cosine similarity of word1 and word2
pass
@abstractmethod
def most_similar_n(self, word, topn):
# return a list of the n most similar words in model
pass
@abstractmethod
def get_vocab(self):
# return a list of vocabulary
pass
@abstractmethod
def word_vec(self, word):
# return an array of the embedding vector belonging to 'word'
pass
@abstractmethod
def may_construct_word_vec(self, word):
# return True if model can get e vector for 'word'
pass
@abstractmethod
def load_model(self, emb_model_dir, emb_model_fn):
# load embedding model
pass
@abstractmethod
def analogy(self, positives, negatives, topn):
# load embedding model
pass
@abstractmethod
def vec_dim(self):
# return dimension of embedding vectors
pass