Commit
•
536de44
1
Parent(s):
d1e7e88
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# T5
|
2 |
+
|
3 |
+
## Overview
|
4 |
+
|
5 |
+
The T5 model was presented in (Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer](https://arxiv.org/pdf/1910.10683.pdf) by Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu.
|
6 |
+
|
7 |
+
The abstract from the paper is the following:
|
8 |
+
|
9 |
+
*Transfer learning, where a model is first pre-trained on a data-rich task before being finetuned on a downstream task, has emerged as a powerful technique in natural language processing (NLP). The effectiveness of transfer learning has given rise to a diversity of approaches, methodology, and practice. In this paper, we explore the landscape of transfer learning techniques for NLP by introducing a unified framework that converts all text-based language problems into a text-to-text format. Our systematic study compares pre-training objectives, architectures, unlabeled data sets, transfer approaches, and other factors on dozens of language understanding tasks. By combining the insights from our exploration with scale and our new “Colossal Clean Crawled Corpus”, we achieve state-of-the-art results on many benchmarks covering summarization, question answering, text classification, and more. To facilitate future work on transfer learning for NLP, we release our data set, pre-trained models, and code.*
|
10 |
+
|
11 |
+
This model was contributed by [stevekola](https://huggingface.co/stevekola). The original code can be found [here](https://github.com/google-research/text-to-text-transfer-transformer).
|
12 |
+
|
13 |
+
**Pretraining Dataset:** [C4](https://www.tensorflow.org/datasets/catalog/c4)
|
14 |
+
|
15 |
+
## Example
|
16 |
+
|
17 |
+
```
|
18 |
+
from huggingface_hub import snapshot_download
|
19 |
+
import tensorflow_text
|
20 |
+
import tensorflow as tf
|
21 |
+
import os
|
22 |
+
|
23 |
+
CACHE_DIR = "hfhub_cache"
|
24 |
+
os.mkdir(CACHE_DIR)
|
25 |
+
|
26 |
+
snapshot_download(repo_id="stevekola/T5", cache_dir=CACHE_DIR)
|
27 |
+
|
28 |
+
saved_model_path = os.path.join(CACHE_DIR, os.listdir(CACHE_DIR)[0])
|
29 |
+
model = tf.saved_model.load(saved_model_path, ["serve"])
|
30 |
+
|
31 |
+
def predict_fn(x):
|
32 |
+
return model.signatures['serving_default'](tf.constant(x))['outputs'].numpy()
|
33 |
+
|
34 |
+
def answer(question):
|
35 |
+
return predict_fn([question])[0].decode('utf-8')
|
36 |
+
|
37 |
+
for question in [
|
38 |
+
"translate English to French: where do we go from here",
|
39 |
+
"translate English to German: where do we go from here",
|
40 |
+
"translate English to Romanian: where do we go from here",
|
41 |
+
"cola sentence: where do we go from here",
|
42 |
+
"stsb sentence1: I'm overjoyed about today's event. sentence2: I'm so happy today",
|
43 |
+
"summarize: Nigeria is losing about 6 billion to 9 billion yearly to the non-passage of the bill, which would have given legal teeth to the water sub-sector for optimal performance like other sectors.",
|
44 |
+
]:
|
45 |
+
print(answer(question))
|
46 |
+
```
|