Shredder commited on
Commit
6c115d6
1 Parent(s): 0a8bb92

Update fincat_utils.py

Browse files
Files changed (1) hide show
  1. fincat_utils.py +9 -7
fincat_utils.py CHANGED
@@ -99,10 +99,12 @@ def bert_embedding_extract(context_text, word):
99
  list_token_embeddings = get_bert_embeddings(tokens_tensor, segments_tensors, model)
100
  word_tokens,tt,st = bert_text_preparation(word, tokenizer)
101
  word_embedding_all = []
102
- for word_tk in word_tokens:
103
- word_index = tokenized_text.index(word_tk)
104
- word_embedding = list_token_embeddings[word_index]
105
- word_embedding_all.append(word_embedding)
106
- word_embedding_mean = np.array(word_embedding_all).mean(axis=0)
107
- return word_embedding_mean
108
-
 
 
 
99
  list_token_embeddings = get_bert_embeddings(tokens_tensor, segments_tensors, model)
100
  word_tokens,tt,st = bert_text_preparation(word, tokenizer)
101
  word_embedding_all = []
102
+ try:
103
+ for word_tk in word_tokens:
104
+ word_index = tokenized_text.index(word_tk)
105
+ word_embedding = list_token_embeddings[word_index]
106
+ word_embedding_all.append(word_embedding)
107
+ word_embedding_mean = np.array(word_embedding_all).mean(axis=0)
108
+ return word_embedding_mean
109
+ except:
110
+ return ['None']