Spaces:
Sleeping
Sleeping
Nguyen Thi Dieu Hien
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -135,7 +135,13 @@ def tokenize_text(text, tokenizer, max_len=256):
|
|
135 |
return_tensors='pt',
|
136 |
)
|
137 |
return tokenized['input_ids'], tokenized['attention_mask']
|
|
|
|
|
|
|
|
|
138 |
|
|
|
|
|
139 |
# Function to get BERT features
|
140 |
def get_bert_features(input_ids, attention_mask, phobert):
|
141 |
with torch.no_grad():
|
@@ -573,4 +579,4 @@ def main():
|
|
573 |
)
|
574 |
|
575 |
if __name__ == '__main__':
|
576 |
-
main()
|
|
|
135 |
return_tensors='pt',
|
136 |
)
|
137 |
return tokenized['input_ids'], tokenized['attention_mask']
|
138 |
+
def get_vector_embedding(padded, attention_mask, phobert):
|
139 |
+
# Obtain features from BERT
|
140 |
+
with torch.no_grad():
|
141 |
+
last_hidden_states = phobert(input_ids=padded, attention_mask=attention_mask)
|
142 |
|
143 |
+
v_features = last_hidden_states[0][:, 0, :].numpy()
|
144 |
+
return v_features
|
145 |
# Function to get BERT features
|
146 |
def get_bert_features(input_ids, attention_mask, phobert):
|
147 |
with torch.no_grad():
|
|
|
579 |
)
|
580 |
|
581 |
if __name__ == '__main__':
|
582 |
+
main()
|