jingwang commited on
Commit
a5743e5
1 Parent(s): 56c7554

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -9
README.md CHANGED
@@ -62,8 +62,8 @@ class FormatPrompt_QA_with_citation():
62
  assert all([ item in instance.keys() for item in self.inputs ]), logging.info(f"instance must have {self.inputs}!")
63
 
64
  prompt = f"""<s> [INST] Context: {str(instance["context"])}\
65
- Question: {str(instance["question"])} [/INST]
66
- Answer: """
67
 
68
  if ('answer' in instance):
69
  if ('citation' in instance):
@@ -82,19 +82,20 @@ formatting_func = FormatPrompt_context_QA()
82
 
83
  # pull model from huggingface
84
  model, tokenizer = FastLanguageModel.from_pretrained(
85
- model_name = "jingwang/mistral_context_qa",
86
  max_seq_length = 2048,
87
  dtype = None,
88
  load_in_4bit = True,
89
  )
90
 
91
 
 
92
  FastLanguageModel.for_inference(model)
93
 
94
  example = {'context': 'John Gadsby Chapman , The Baptism of Pocahontas (1840). A copy is on display in the Rotunda of the United States Capitol . During her stay at Henricus, Pocahontas met John Rolfe. Rolfe\'s English-born wife Sarah Hacker and child Bermuda had died on the way to Virginia after the wreck of the ship Sea Venture on the Summer Isles, now known as Bermuda. He established the Virginia plantation Varina Farms , where he cultivated a new strain of tobacco . Rolfe was a pious man and agonized over the potential moral repercussions of marrying a heathen, though in fact Pocahontas had accepted the Christian faith and taken the baptismal name Rebecca. In a long letter to the governor requesting permission to wed her, he expressed his love for Pocahontas and his belief that he would be saving her soul. He wrote that he was: motivated not by the unbridled desire of carnal affection, but for the good of this plantation, for the honor of our country, for the Glory of God, for my own salvation... namely Pocahontas, to whom my hearty and best thoughts are, and have been a long time so entangled, and enthralled in so intricate a labyrinth that I was even a-wearied to unwind myself thereout. [41] The couple were married on April 5, 1614, by chaplain Richard Buck , probably at Jamestown. For two years they lived at Varina Farms, across the James River from Henricus. Their son Thomas was born in January 1615. [42] The marriage created a climate of peace between the Jamestown colonists and Powhatan\'s tribes; it endured for eight years as the "Peace of Pocahontas". [43] In 1615, Ralph Hamor wrote, "Since the wedding we have had friendly commerce and trade not only with Powhatan but also with his subjects round about us." [44] The marriage was controversial in the British court at the time because "a commoner" had "the audacity" to marry a "princess." [45] [46]',
95
  'question': 'Who did Pocahontas marry?',
96
- 'answer': 'Pocahontas married John Rolfe',
97
- 'citation': 'The couple were married on April 5, 1614, by chaplain Richard Buck , probably at Jamestown.'
98
  }
99
 
100
 
@@ -105,7 +106,7 @@ input_length = inputs.input_ids.shape[-1]
105
  with torch.no_grad():
106
  output = model.generate(**inputs,
107
  do_sample=False,
108
- temperature=0.1,
109
  max_new_tokens=1024,
110
  pad_token_id=tokenizer.eos_token_id,
111
  use_cache=False,
@@ -116,11 +117,9 @@ with torch.no_grad():
116
  )
117
  print(response)
118
 
119
-
120
-
121
  ```
122
 
123
  ```
124
- >> {"answer": "Pocahontas married John Rolfe", "citation": "Rolfe's English-born wife Sarah Hacker and child Bermuda had died on the way to Virginia after the wreck of the ship Sea Venture on the Summer Isles, now known as Bermuda. He established the Virginia plantation Varina Farms , where he cultivated a new strain of tobacco . Rolfe was a pious man and agonized over the potential moral repercussions of marrying a heathen, though in fact Pocahontas had accepted the Christian"}
125
 
126
  ```
 
62
  assert all([ item in instance.keys() for item in self.inputs ]), logging.info(f"instance must have {self.inputs}!")
63
 
64
  prompt = f"""<s> [INST] Context: {str(instance["context"])}\
65
+ Question: {str(instance["question"])}
66
+ Answer: [/INST]"""
67
 
68
  if ('answer' in instance):
69
  if ('citation' in instance):
 
82
 
83
  # pull model from huggingface
84
  model, tokenizer = FastLanguageModel.from_pretrained(
85
+ model_name = "jingwang/mistral_qa_citation",
86
  max_seq_length = 2048,
87
  dtype = None,
88
  load_in_4bit = True,
89
  )
90
 
91
 
92
+ # inference
93
  FastLanguageModel.for_inference(model)
94
 
95
  example = {'context': 'John Gadsby Chapman , The Baptism of Pocahontas (1840). A copy is on display in the Rotunda of the United States Capitol . During her stay at Henricus, Pocahontas met John Rolfe. Rolfe\'s English-born wife Sarah Hacker and child Bermuda had died on the way to Virginia after the wreck of the ship Sea Venture on the Summer Isles, now known as Bermuda. He established the Virginia plantation Varina Farms , where he cultivated a new strain of tobacco . Rolfe was a pious man and agonized over the potential moral repercussions of marrying a heathen, though in fact Pocahontas had accepted the Christian faith and taken the baptismal name Rebecca. In a long letter to the governor requesting permission to wed her, he expressed his love for Pocahontas and his belief that he would be saving her soul. He wrote that he was: motivated not by the unbridled desire of carnal affection, but for the good of this plantation, for the honor of our country, for the Glory of God, for my own salvation... namely Pocahontas, to whom my hearty and best thoughts are, and have been a long time so entangled, and enthralled in so intricate a labyrinth that I was even a-wearied to unwind myself thereout. [41] The couple were married on April 5, 1614, by chaplain Richard Buck , probably at Jamestown. For two years they lived at Varina Farms, across the James River from Henricus. Their son Thomas was born in January 1615. [42] The marriage created a climate of peace between the Jamestown colonists and Powhatan\'s tribes; it endured for eight years as the "Peace of Pocahontas". [43] In 1615, Ralph Hamor wrote, "Since the wedding we have had friendly commerce and trade not only with Powhatan but also with his subjects round about us." [44] The marriage was controversial in the British court at the time because "a commoner" had "the audacity" to marry a "princess." [45] [46]',
96
  'question': 'Who did Pocahontas marry?',
97
+ #'answer': 'Pocahontas married John Rolfe',
98
+ #'citation': 'The couple were married on April 5, 1614, by chaplain Richard Buck , probably at Jamestown.'
99
  }
100
 
101
 
 
106
  with torch.no_grad():
107
  output = model.generate(**inputs,
108
  do_sample=False,
109
+ temperature=0.5,
110
  max_new_tokens=1024,
111
  pad_token_id=tokenizer.eos_token_id,
112
  use_cache=False,
 
117
  )
118
  print(response)
119
 
 
 
120
  ```
121
 
122
  ```
123
+ >> {"answer": "Pocahontas married John Rolfe", "citation": "In a long letter to the governor requesting permission to wed her, he expressed his love for Pocahontas and his belief that he would be saving her soul. He wrote that he was: motivated not by the unbridled desire of carnal affection, but for the good of this plantation, for the honor of our country, for the Glory of God, for my own salvation... namely Pocahontas"}
124
 
125
  ```