Update README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
# Roberta Large STS-B
|
| 4 |
+
|
| 5 |
+
This model is a fine tuned RoBERTA model over STS-B.
|
| 6 |
+
It was trained with these params:
|
| 7 |
+
!python /content/transformers/examples/run_glue.py \
|
| 8 |
+
--model_type roberta \
|
| 9 |
+
--model_name_or_path roberta-large \
|
| 10 |
+
--task_name STS-B \
|
| 11 |
+
--do_train \
|
| 12 |
+
--do_eval \
|
| 13 |
+
--do_lower_case \
|
| 14 |
+
--data_dir /content/glue_data/STS-B/ \
|
| 15 |
+
--max_seq_length 128 \
|
| 16 |
+
--per_gpu_eval_batch_size=8 \
|
| 17 |
+
--per_gpu_train_batch_size=8 \
|
| 18 |
+
--learning_rate 2e-5 \
|
| 19 |
+
--num_train_epochs 3.0 \
|
| 20 |
+
--output_dir /content/roberta-sts-b
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
## How to run
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
import toolz
|
| 30 |
+
import torch
|
| 31 |
+
batch_size = 6
|
| 32 |
+
|
| 33 |
+
def roberta_similarity_batches(to_predict):
|
| 34 |
+
batches = toolz.partition(batch_size, to_predict)
|
| 35 |
+
similarity_scores = []
|
| 36 |
+
for batch in batches:
|
| 37 |
+
sentences = [(sentence_similarity["sent1"], sentence_similarity["sent2"]) for sentence_similarity in batch]
|
| 38 |
+
batch_scores = similarity_roberta(model, tokenizer,sentences)
|
| 39 |
+
similarity_scores = similarity_scores + batch_scores[0].cpu().squeeze(axis=1).tolist()
|
| 40 |
+
return similarity_scores
|
| 41 |
+
|
| 42 |
+
def similarity_roberta(model, tokenizer, sent_pairs):
|
| 43 |
+
batch_token = tokenizer.batch_encode_plus(sent_pairs, pad_to_max_length=True, max_length=500)
|
| 44 |
+
res = model(torch.tensor(batch_token['input_ids']).cuda(), attention_mask=torch.tensor(batch_token["attention_mask"]).cuda())
|
| 45 |
+
return res
|
| 46 |
+
|
| 47 |
+
similarity_roberta(model, tokenizer, [('NEW YORK--(BUSINESS WIRE)--Rosen Law Firm, a global investor rights law firm, announces it is investigating potential securities claims on behalf of shareholders of Vale S.A. ( VALE ) resulting from allegations that Vale may have issued materially misleading business information to the investing public',
|
| 48 |
+
'EQUITY ALERT: Rosen Law Firm Announces Investigation of Securities Claims Against Vale S.A. – VALE')])
|
| 49 |
+
|
| 50 |
+
```
|