update readme
Browse files- README.md +4 -0
- README.md~ +0 -81
README.md
CHANGED
|
@@ -16,6 +16,10 @@ metrics:
|
|
| 16 |
---
|
| 17 |
# T5 Base with QA + Summary + Emotion
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
## Description
|
| 20 |
|
| 21 |
This model was finetuned on the CoQa, Squad 2, GoEmotions and CNN/DailyMail.
|
|
|
|
| 16 |
---
|
| 17 |
# T5 Base with QA + Summary + Emotion
|
| 18 |
|
| 19 |
+
## Dependencies
|
| 20 |
+
|
| 21 |
+
Requires transformers>=4.0.0
|
| 22 |
+
|
| 23 |
## Description
|
| 24 |
|
| 25 |
This model was finetuned on the CoQa, Squad 2, GoEmotions and CNN/DailyMail.
|
README.md~
DELETED
|
@@ -1,81 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
language:
|
| 3 |
-
- en
|
| 4 |
-
tags:
|
| 5 |
-
- question-answering
|
| 6 |
-
- summarization
|
| 7 |
-
- emotion-detection
|
| 8 |
-
license: Apache 2.0
|
| 9 |
-
datasets:
|
| 10 |
-
- coqa
|
| 11 |
-
- squad_v2
|
| 12 |
-
- go_emotions
|
| 13 |
-
- cnn_dailymail
|
| 14 |
-
metrics:
|
| 15 |
-
- f1
|
| 16 |
-
---
|
| 17 |
-
# T5 Base with QA + Summary + Emotion
|
| 18 |
-
|
| 19 |
-
## Description
|
| 20 |
-
|
| 21 |
-
This model was finetuned on the CoQa, Squad 2, GoEmotions and CNN/DailyMail.
|
| 22 |
-
|
| 23 |
-
It achieves a score of **F1 76.7** on the Squad 2 dev set and a score of **F1 68.5** on the CoQa dev set.
|
| 24 |
-
|
| 25 |
-
Summarisation and emotion detection has not been evaluated yet.
|
| 26 |
-
|
| 27 |
-
## Usage
|
| 28 |
-
|
| 29 |
-
### Question answering
|
| 30 |
-
|
| 31 |
-
```python
|
| 32 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 33 |
-
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
|
| 34 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-base")
|
| 35 |
-
|
| 36 |
-
def get_answer(question, prev_qa, context):
|
| 37 |
-
input_text = [f"q: {qa[0]} a: {qa[1]}" for qa in prev_qa]
|
| 38 |
-
input_text.append(f"q: {question}")
|
| 39 |
-
input_text.append(f"c: {context}")
|
| 40 |
-
input_text = " ".join(input_text)
|
| 41 |
-
features = tokenizer([input_text], return_tensors='pt')
|
| 42 |
-
tokens = model.generate(input_ids=features['input_ids'],
|
| 43 |
-
attention_mask=features['attention_mask'], max_length=64)
|
| 44 |
-
return tokenizer.decode(tokens[0], skip_special_tokens=True)
|
| 45 |
-
|
| 46 |
-
print(get_answer("Why is the moon yellow?", "I'm not entirely sure why the moon is yellow.")) # unknown
|
| 47 |
-
|
| 48 |
-
context = "Elon Musk left OpenAI to avoid possible future conflicts with his role as CEO of Tesla."
|
| 49 |
-
|
| 50 |
-
print(get_answer("Why not?", [("Does Elon Musk still work with OpenAI", "No")], context)) # to avoid possible future conflicts with his role as CEO of Tesla
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
### Summarisation
|
| 54 |
-
|
| 55 |
-
```python
|
| 56 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 57 |
-
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
|
| 58 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-base")
|
| 59 |
-
|
| 60 |
-
def summary(context):
|
| 61 |
-
input_text = f"summarize: {context}"
|
| 62 |
-
features = tokenizer([input_text], return_tensors='pt')
|
| 63 |
-
tokens = model.generate(input_ids=features['input_ids'],
|
| 64 |
-
attention_mask=features['attention_mask'], max_length=64)
|
| 65 |
-
return tokenizer.decode(tokens[0], skip_special_tokens=True)
|
| 66 |
-
```
|
| 67 |
-
|
| 68 |
-
### Emotion detection
|
| 69 |
-
|
| 70 |
-
```python
|
| 71 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
| 72 |
-
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
|
| 73 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-base")
|
| 74 |
-
|
| 75 |
-
def emotion(context):
|
| 76 |
-
input_text = f"emotion: {context}"
|
| 77 |
-
features = tokenizer([input_text], return_tensors='pt')
|
| 78 |
-
tokens = model.generate(input_ids=features['input_ids'],
|
| 79 |
-
attention_mask=features['attention_mask'], max_length=64)
|
| 80 |
-
return tokenizer.decode(tokens[0], skip_special_tokens=True)
|
| 81 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|