Guest User

Untitled

a guest
Mar 18th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. # class XLSummary(BaseTextDataset):
  2. # def __init__(self, tokenizer: BaseTokenizer, max_seq_length: int = 128, dataset_url: Optional[str] = None, save_dir: str = "./datasets", filename: str = "xlsum-en-300k.json"):
  3. # super().__init__(tokenizer, max_seq_length, dataset_url)
  4.  
  5. # def load_data(self, dataset_url: Optional[str] = None, save_dir: str = "./datasets", filename: str = "xlsum-en-300k.json"):
  6. # import base64
  7.  
  8. # N_STEPS_PER_TQDM_UPDATE = 10
  9. # steps_taken = 0
  10.  
  11. # """
  12. # import base64
  13. # strb = bytes("Hi", 'utf-8')
  14. # encoded = base64.b64encode(strb).decode('utf-8')
  15. # print(encoded)
  16. # """
  17.  
  18. # if not os.path.isfile(dataset_url):
  19. # raise Exception(f"`{dataset_url}` does not exist!")
  20.  
  21. # with open(dataset_url, 'r') as file:
  22. # data = json.load(file)
  23.  
  24. # # A running list of previous question/answer pairs to augment the current entry.
  25. # chat = ChatHistory()
  26.  
  27. # tqdm_bar = tqdm(total=len(data), desc="Loading", position=0, leave=True)
  28. # for i, entry in enumerate(data):
  29. # steps_taken += 1
  30.  
  31. # if steps_taken % N_STEPS_PER_TQDM_UPDATE == 0:
  32. # tqdm_bar.set_description(f"Processing {steps_taken}/{len(data)}")
  33. # tqdm_bar.update(N_STEPS_PER_TQDM_UPDATE)
  34.  
  35. # document = entry['text']
  36. # summary = entry['summary']
  37.  
  38. # # Assistant: OK!
  39. # agent_confirmation = random.choice(self.CONFIRMATIONS)
  40. # agent_remark = random.choice(self.REMARKS)
  41. # # Newlines, breaks etc.
  42. # _whitespace1 = self.make_whitespace()
  43. # _whitespace2 = self.make_whitespace()
  44.  
  45. # as_json = json.dumps({
  46. # "summary": summary,
  47. # }, indent=4)
  48.  
  49. # as_json_with_original = json.dumps({
  50. # "original": document,
  51. # "summary": summary,
  52. # }, indent=4)
  53.  
  54. # as_json_with_b64 = json.dumps({
  55. # "summary": summary,
  56. # "b64": base64.b64encode(bytes(summary, 'utf-8')).decode('utf-8'),
  57. # }, indent=4)
  58.  
  59. # qa = [
  60. # {
  61. # "question": f"{document}{_whitespace2}Summarise^",
  62. # "response": f"{agent_confirmation} Here's a summary of the document you provided:\n\n{summary}\n\n{agent_remark}",
  63. # },
  64. # {
  65. # "question": f"Please summarise the following document:{_whitespace1}{document}{_whitespace2}Make sure to output nothing else but the summary.",
  66. # "response": f"{summary}",
  67. # },
  68. # {
  69. # "question": f"ONLY summarise the document below.{_whitespace1}{document}{_whitespace2}",
  70. # "response": f"{summary}",
  71. # },
  72. # {
  73. # "question": f"Can you summarise the document below?{_whitespace1}{document}{_whitespace2}",
  74. # "response": f"{agent_confirmation} I've provided a brief explanation of the text you supplied above:\n\n{summary}\n\n{agent_remark}",
  75. # },
  76. # {
  77. # "question": f"{_whitespace1}{document}{_whitespace2}I want you to summarise the document provided, however I want you to output it in JSON format.",
  78. # "response": f"{agent_confirmation} I'll provide the summary as a key in the JSON payload below:\n```json\n{as_json}\n```\n",
  79. # },
  80. # {
  81. # "question": f"Please can you summarise this document:{_whitespace1}{document}{_whitespace2}Are you able to output it as JSON with a 'b64' parameter with the base64 encoding?",
  82. # "response": f"{agent_confirmation} Here's a summary of the text you provided with the base64 encoding attached.\n```json\n{as_json_with_b64}\n```\n{agent_remark}",
  83. # },
  84. # {
  85. # "question": f"<Document>{_whitespace1}{document}{_whitespace2}</Document>\n\nSummarize document above as a JSON payload, nothing else.",
  86. # "response": f"```json\n{as_json}\n```",
  87. # },
  88. # {
  89. # "question": f"<Document>{_whitespace1}{document}{_whitespace2}</Document>\n\nSummarize document above as a JSON payload and include the 'original' text in the payload.",
  90. # "response": f"Sure, here's the JSON data as requested:\n\n```json\n{as_json_with_original}\n```\n{agent_remark}",
  91. # },
  92. # ]
  93.  
  94. # selection = random.choice(qa)
  95.  
  96. # question = selection['question']
  97. # response = selection['response']
  98.  
  99. # chat.add_message(role="Human", content=question)
  100. # chat.add_message(role="Assistant", content=response)
  101. # encoded = self.tokenizer.encode(chat.transcript())
  102.  
  103. # self.dataset.append(encoded)
  104. # return self.dataset
Add Comment
Please, Sign In to add comment