Ihor commited on
Commit
173cf62
1 Parent(s): 6ac3d8e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -5
README.md CHANGED
@@ -19,10 +19,13 @@ This is an encoder-decoder model that was trained on various information extract
19
  First of all, initialize the model:
20
  ```python
21
  from transformers import T5Tokenizer, T5ForConditionalGeneration
 
 
 
22
 
23
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
24
 
25
- model = T5ForConditionalGeneration.from_pretrained("knowledgator/t5-for-ie")
26
  ```
27
 
28
  You need to set a prompt and put it with text to the model, below are examples of how to use it for different tasks:
@@ -30,7 +33,7 @@ You need to set a prompt and put it with text to the model, below are examples o
30
  **named entity recognition**
31
  ```python
32
  input_text = "Extract entity types from the text: <e1>Kyiv</e1> is the capital of <e2>Ukraine</e2>."
33
- input_ids = tokenizer(input_text, return_tensors="pt").input_ids
34
 
35
  outputs = model.generate(input_ids)
36
  print(tokenizer.decode(outputs[0]))
@@ -39,7 +42,7 @@ print(tokenizer.decode(outputs[0]))
39
  **text classification**
40
  ```python
41
  input_text = "Classify the following text into the most relevant categories: Kyiv is the capital of Ukraine"
42
- input_ids = tokenizer(input_text, return_tensors="pt").input_ids
43
 
44
  outputs = model.generate(input_ids)
45
  print(tokenizer.decode(outputs[0]))
@@ -48,7 +51,7 @@ print(tokenizer.decode(outputs[0]))
48
  **relation extraction**
49
  ```python
50
  input_text = "Extract relations between entities in the text: <e1>Kyiv</e1> is the capital of <e2>Ukraine</e2>."
51
- input_ids = tokenizer(input_text, return_tensors="pt").input_ids
52
 
53
  outputs = model.generate(input_ids)
54
  print(tokenizer.decode(outputs[0]))
@@ -78,7 +81,7 @@ classifier = TextClassifier(
78
  labels=['default'],
79
  model=model,
80
  tokenizer=tokenizer,
81
- device='cuda:0' #if cuda
82
  )
83
  classifier.initialize_labels_trie(labels)
84
 
 
19
  First of all, initialize the model:
20
  ```python
21
  from transformers import T5Tokenizer, T5ForConditionalGeneration
22
+ import torch
23
+
24
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device('cpu')
25
 
26
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
27
 
28
+ model = T5ForConditionalGeneration.from_pretrained("knowledgator/t5-for-ie").to(device)
29
  ```
30
 
31
  You need to set a prompt and put it with text to the model, below are examples of how to use it for different tasks:
 
33
  **named entity recognition**
34
  ```python
35
  input_text = "Extract entity types from the text: <e1>Kyiv</e1> is the capital of <e2>Ukraine</e2>."
36
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
37
 
38
  outputs = model.generate(input_ids)
39
  print(tokenizer.decode(outputs[0]))
 
42
  **text classification**
43
  ```python
44
  input_text = "Classify the following text into the most relevant categories: Kyiv is the capital of Ukraine"
45
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
46
 
47
  outputs = model.generate(input_ids)
48
  print(tokenizer.decode(outputs[0]))
 
51
  **relation extraction**
52
  ```python
53
  input_text = "Extract relations between entities in the text: <e1>Kyiv</e1> is the capital of <e2>Ukraine</e2>."
54
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to(device)
55
 
56
  outputs = model.generate(input_ids)
57
  print(tokenizer.decode(outputs[0]))
 
81
  labels=['default'],
82
  model=model,
83
  tokenizer=tokenizer,
84
+ device=device #if cuda
85
  )
86
  classifier.initialize_labels_trie(labels)
87