enter image description hereenter image description hereI want to combine two models for my training data, but I do not know why it's always wrong. My topic is get one embedding, then adjust the length, combine two embedding in other def() function
# Please comment your code
import numpy as np
def Concatenation (posts, model):
emb_table = []
for i in posts:
for word in i:
if word in model:
emb_table.append(model.wv[word])
else:
emb_table.append([0]*model.vector_size)
return emb_table
len_list = [len(s) for s in traning_post_new]
seq_length = max(len_list)
seq_length
# # Padding and encoding
# def encode_and_add_padding(sentences, seq_length, word_index):
# sent_encoded = []
# for sent in sentences:
# temp_encoded = [word_index[word] if word in word_index else word_index['[UNKNOWN]'] for word in sent]
# if len(temp_encoded) < seq_length:
# temp_encoded += [word_index['[PAD]']] * (seq_length - len(temp_encoded))
# sent_encoded.append(temp_encoded)
# return sent_encoded
# sent_encoded = encode_and_add_padding(sentences, seq_length, word_index)
# print(sent_encoded)
def encode_and_add_padding(posts, model1, model2):
for i in range(len(posts)): # i is index
if len(posts[i]) < seq_length:
posts[i].extend(["[PAD]"]*(seq_length-len(posts[i])))
else:
posts[i] = posts[i][:seq_length]
embedding1 = Concatenation (posts, model1)
embedding2 = Concatenation (posts, model2)
print(embedding1.shape)
final_embedding = np.concatenate((embedding1,embedding2), 0)
return final_embedding