我有一列行文本。从行文本列中,我会得到类似于产品名称列表的名称。我正在使用 Doc2Vec 来解决这个问题。但是我的成绩一直很差。哪个是解决这个问题的正确方法?
我的数据如下: LINE TEXT: 托盘 10kg 鸡肉weldcote 金属物流 100th main, bolulvedour ave 19th main ST john 5670987
我用来获得最相似名称的产品列表是 mat_subset=[英国尺码 10 鞋、超干饰边、重 10 公斤的盒子、托盘等]
我的行文本是我的 OCR 输出,非常不错。我使用的 Doc2Vec 代码如下。
s_data=mat['LINETEXT']
line_txt = pd.DataFrame()
line_txt['sentences']=s_data
line_txt['sentences']=line_txt['sentences'].astype(str)
line_txt['tokenized_sents'] = line_txt.apply(lambda row: nltk.word_tokenize(row['sentences']), axis=1)
sentences= []
for item_no, line in enumerate(line_txt['tokenized_sents'].values.tolist()):
sentences.append(LabeledSentence(line,[item_no]))
# MODEL PARAMETERS
dm = 1 # 1 for distributed memory(default); 0 for dbow
cores = multiprocessing.cpu_count()
size = 300
context_window = 50
seed = 42
min_count = 1
alpha = 0.5
max_iter = 200
# BUILD MODEL
model = gensim.models.doc2vec.Doc2Vec(documents = sentences,
dm = dm,
alpha = alpha, # initial learning rate
seed = seed,
min_count = min_count, # ignore words with freq less than min_count
max_vocab_size = None, #
window = context_window, # the number of words before and after to be used as context
size = size, # is the dimensionality of the feature vector
sample = 1e-4, # ?
negative = 5, # ?
workers = cores, # number of cores
iter = max_iter)
overalldf=[]
for line in mat_subset:
infer_vector = model.infer_vector(line)
similar_documents = model.docvecs.most_similar([infer_vector], topn = 10)
df.columns=["sentence",'Similarity']
overalldf.append(df)
final=pd.concat(overalldf)
这是我用过的代码。其中 mat_subset 是我的产品名称列表。我对python很陌生,如果我做错了什么,请纠正我