vblagoje commited on
Commit
b119bed
1 Parent(s): a9cee57

Initial README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md CHANGED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ datasets:
4
+ - vblagoje/lfqa
5
+ - vblagoje/lfqa_support_docs
6
+ license: mit
7
+ ---
8
+
9
+ ## Usage
10
+
11
+
12
+ ```python
13
+ import torch
14
+ from transformers import AutoTokenizer, AutoModel, AutoModelForSeq2SeqLM
15
+
16
+ model_name = "vblagoje/bart_lfqa"
17
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
18
+
19
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
20
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
21
+ model = model.to(device)
22
+
23
+ # it all starts with a question/query
24
+ query = "Why does water heated to room temperature feel colder than the air around it?"
25
+
26
+ # given the question above suppose these documents below were found in some document store
27
+ documents = ["when the skin is completely wet. The body continuously loses water by...",
28
+ "at greater pressures. There is an ambiguity, however, as to the meaning of the terms 'heating' and 'cooling'...",
29
+ "are not in a relation of thermal equilibrium, heat will flow from the hotter to the colder, by whatever pathway...",
30
+ "air condition and moving along a line of constant enthalpy toward a state of higher humidity. A simple example ...",
31
+ "Thermal contact conductance In physics, thermal contact conductance is the study of heat conduction between solid ..."]
32
+
33
+ # concatenate question and support documents into BART input
34
+ conditioned_doc = "<P> " + " <P> ".join([d for d in documents])
35
+ query_and_docs = "question: {} context: {}".format(query, conditioned_doc)
36
+
37
+ model_input = tokenizer(query_and_docs, truncation=True, padding=True, return_tensors="pt")
38
+
39
+ generated_answers_encoded = model.generate(input_ids=model_input["input_ids"].to(device),
40
+ attention_mask=model_input["attention_mask"].to(device),
41
+ min_length=64,
42
+ max_length=256,
43
+ do_sample=False,
44
+ early_stopping=True,
45
+ num_beams=8,
46
+ temperature=1.0,
47
+ top_k=None,
48
+ top_p=None,
49
+ eos_token_id=tokenizer.eos_token_id,
50
+ no_repeat_ngram_size=3,
51
+ num_return_sequences=1)
52
+ tokenizer.batch_decode(generated_answers_encoded, skip_special_tokens=True,clean_up_tokenization_spaces=True)
53
+
54
+ # below is the abstractive answer generated by the model
55
+ ["When you heat water to room temperature, it loses heat to the air around it. When you cool it down, it gains heat back from the air, which is why it feels colder than the air surrounding it. It's the same reason why you feel cold when you turn on a fan. The air around you is losing heat, and the water is gaining heat."]
56
+
57
+ ```
58
+
59
+ ## Author
60
+ - Vladimir Blagojevic: `dovlex [at] gmail.com` [Twitter](https://twitter.com/vladblagoje) | [LinkedIn](https://www.linkedin.com/in/blagojevicvladimir/)