mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-30 11:50:06 +08:00
16 KiB
16 KiB
In [82]:
xp3_list = [
"Code Miscellaneous",
"CodeComplex",
"Docstring Corpus",
"GreatCode",
"State Changes",
"Closed-book QA",
"Hotpot QA",
"Trivia QA",
"Web Questions",
"Wiki QA",
"Extractive QA",
"Adversarial QA",
"CMRC2018",
"DRCD",
"DuoRC",
"MLQA",
"Quoref",
"ReCoRD",
"ROPES",
"SQuAD v2",
"xQuAD",
"TyDI QA",
"Primary",
"Goldp",
"Multiple-Choice QA",
"ARC",
"C3",
"CoS-E",
"Cosmos",
"DREAM",
"MultiRC",
"OpenBookQA",
"PiQA",
"QUAIL",
"QuaRel",
"QuaRTz",
"QASC",
"RACE",
"SciQ",
"Social IQA",
"Wiki Hop",
"WiQA",
"Paraphrase Identification",
"MRPC",
"PAWS",
"PAWS-X",
"QQP",
"Program Synthesis",
"APPS",
"CodeContests",
"JupyterCodePairs",
"MBPP",
"NeuralCodeSearch",
"XLCoST",
"Structure-to-text",
"Common Gen",
"Wiki Bio",
"Sentiment",
"Amazon",
"App Reviews",
"IMDB",
"Rotten Tomatoes",
"Yelp",
"Simplification",
"BiSECT",
"Summarization",
"CNN Daily Mail",
"Gigaword",
"MultiNews",
"SamSum",
"Wiki-Lingua",
"XLSum",
"XSum",
"Topic Classification",
"AG News",
"DBPedia",
"TNEWS",
"TREC",
"CSL",
"Translation",
"Flores-200",
"Tatoeba",
"Word Sense disambiguation",
"WiC",
"XL-WiC",
"Evaluation datasets (included in xP3all except for HumanEval)",
"Natural Language Inference",
"ANLI",
"CB",
"RTE",
"XNLI",
"Coreference Resolution",
"Winogrande",
"XWinograd",
"Program Synthesis",
"HumanEval",
"Sentence Completion",
"COPA",
"Story Cloze",
"XCOPA",
"XStoryCloze",
"Additional xP3all datasets",
"Coreference Resolution",
"WSC (Fixed)",
"Sentence Completion",
"HellaSwag",
"Translation",
"MultiEurlex",
]In [83]:
unifiedQA_list = [
"SQuAD 1.1",
"SQuAD 2",
"NewsQA",
"Quoref",
"ROPES",
"NarrativeQA",
"DROP",
"NaturalQuestions",
"MCTest",
"RACE",
"OpenBookQA",
"ARC",
"CommonsenseQA",
"QASC",
"PhysicalIQA",
"SocialIQA",
"Winogrande",
"BoolQ",
"MultiRC (yes/no)",
"BoolQ-NP",
]In [84]:
for ds in unifiedQA_list:
if ds not in xp3_list:
print(ds)SQuAD 1.1 SQuAD 2 NewsQA NarrativeQA DROP NaturalQuestions MCTest CommonsenseQA PhysicalIQA SocialIQA BoolQ MultiRC (yes/no) BoolQ-NP
In [85]:
from typing import TypeVar, List, Dict, Any, Literal
from json import JSONEncoder
T = TypeVar("T", bound="ConversationTreeNode")
class ConversationTreeNode:
text: str # The text of the node
role: Literal["prompter", "assistant"] # Whether the node is a user prompt/follow-up or an assistant response
children: List[T] # The children of the node (if you have a linear conversation, this will be of length 0 or 1)
metadata: Dict[str, Any] # Node metadata (see below)
def __init__(
self, text: str, role: Literal["prompter", "assistant"], children: List[T], metadata: Dict[str, Any]
) -> None:
self.text = text
self.role = role
self.children = children
self.metadata = metadata
class ConversationTree:
root: ConversationTreeNode # The node containing the initial prompt
metadata: Dict[str, Any] # Tree metadata, different from root node metadata.
def __init__(self, root: ConversationTreeNode, metadata: Dict[str, Any]) -> None:
self.root = root
self.metadata = metadata
# subclass JSONEncoder
class TreeEncoder(JSONEncoder):
def default(self, o):
return o.__dict__In [86]:
import pandas as pd
import jsonIn [87]:
def convert_unified_qa(dataset_url):
# download using pandas
ds = pd.read_csv(dataset_url, on_bad_lines="skip", names=["Question", "Answer"], sep="\t")
# get name for metatdata
ds_name = dataset_url.split("/unifiedqa/data/")[1].split("/")[0]
# create conversation forest
conversation_forest = []
for item in ds.itertuples():
# build nodes and tree
root = ConversationTreeNode(text=item.Question, role="prompter", children=[], metadata=None)
child = ConversationTreeNode(text=item.Answer, role="assistant", children=[], metadata=None)
root.children.append(child)
conversation_tree = ConversationTree(root=root, metadata={"dataset": ds_name})
conversation_forest.append(conversation_tree)
conversation_forest_json = [
json.loads(TreeEncoder().encode(conversation_tree)) for conversation_tree in conversation_forest
]
print(json.dumps(conversation_forest_json, indent=4), file=open(f"./{ds_name}.json", "w+"))
print("*****", ds_name, "****")
print(ds.head(2))
print("....")In [88]:
urls = [
"https://storage.googleapis.com/unifiedqa/data/natural_questions/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/narrativeqa/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/newsqa/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/drop/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/commonsenseqa/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/physical_iqa/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/social_iqa/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/boolq/train.tsv",
"https://storage.googleapis.com/unifiedqa/data/boolq_np/train.tsv",
]In [77]:
for url in urls:
convert_unified_qa(url)***** natural_questions ****
Question \
0 which is the most common use of opt-in e-mail ...
1 how i.met your mother who is the mother?
Answer
0 a newsletter sent to an advertising firm's cus...
1 Tracy McConnell
....
***** narrativeqa ****
Question \
0 Who is Miss Delmer? \n At Madeline Hall, an o...
1 Who is Miss Delmer? \n At Madeline Hall, an o...
Answer
0 the elderly spinster aunt of the Earl de Vers...
1 She's Captail Delmar's aunt.
....
***** newsqa ****
Question Answer
0 How many Americans are part of the federal foo... 31 million
1 How much did Sean Callebs live on? \n (CNN) --... $176
....
***** drop ****
Question Answer
0 How many points did the buccaneers need to tie... 3
1 How many field goals did the Lions score? \n T... 2
....
***** commonsenseqa ****
Question Answer
0 The sanctions against the school were a punish... ignore
1 Sammy wanted to go to where the people were. ... populated areas
....
***** physical_iqa ****
Question \
0 When boiling butter, when it's ready, you can ...
1 To permanently attach metal legs to a chair, y...
Answer
0 Pour it into a jar
1 Weld the metal together to get it to stay fir...
....
***** social_iqa ****
Question Answer
0 How would Others feel as a result? \n (A) like... like attending
1 What will Others want to do next? \n (A) disag... get to work
....
***** boolq ****
Question Answer
0 can you buy beer at a grocery store in pa? \n ... yes
1 is the baby in fuller house a twin? \n (List o... yes
....
***** boolq_np ****
Question Answer
0 do iran and afghanistan write the same languag... yes
1 do iran and afghanistan read the same language... yes
....
In [ ]: