π English Gpt 4 0314 ReferenceΒΆ
cards.arena_hard.generation.english_gpt_4_0314_reference
TaskCard(
loader=LoadJsonFile(
files={
"questions": "https://raw.githubusercontent.com/lmarena/arena-hard-auto/57451f35d2be7fef9f05d5567f36e4c959bb6630/data/arena-hard-v0.1/question.jsonl",
"model_answer": "https://raw.githubusercontent.com/lmarena/arena-hard-auto/57451f35d2be7fef9f05d5567f36e4c959bb6630/data/arena-hard-v0.1/model_answer/gpt-4-0314.jsonl",
},
lines=True,
data_classification_policy=[
"public",
],
),
preprocess_steps=[
Rename(
field_to_field={
"cluster": "group",
},
apply_to_streams=[
"questions",
],
),
Copy(
field_to_field={
"prompt": "model_input",
},
apply_to_streams=[
"questions",
],
),
Set(
fields={
"reference_model": "gpt-4-0314",
},
apply_to_streams=[
"questions",
],
),
Copy(
field_to_field={
"messages/1/content/answer": "reference_model_output",
},
apply_to_streams=[
"model_answer",
],
),
Rename(
field_to_field={
"model": "reference_model",
},
apply_to_streams=[
"model_answer",
],
),
Apply(
function="str.lower",
to_field="reference_model",
apply_to_streams=[
"model_answer",
],
_argv=[
"reference_model",
],
),
JoinStreams(
left_stream="questions",
right_stream="model_answer",
how="inner",
on=[
"uid",
"reference_model",
],
new_stream_name="test",
),
DeleteSplits(
splits=[
"questions",
"model_answer",
],
),
SelectFields(
fields=[
"uid",
"category",
"model_input",
"reference_model",
"reference_model_output",
],
),
Rename(
field_to_field={
"uid": "question_id",
"model_input": "input",
"category": "group",
"reference_model_output": "output",
},
),
Set(
fields={
"type_of_input": "prompt",
"type_of_output": "answer",
},
),
],
task="tasks.generation",
templates=[
"templates.generation.empty",
],
)
[source]from unitxt.loaders import LoadJsonFile
from unitxt.operators import Apply, Copy, Rename, SelectFields, Set
from unitxt.stream_operators import DeleteSplits, JoinStreams
Explanation about TaskCardΒΆ
TaskCard delineates the phases in transforming the source dataset into model input, and specifies the metrics for evaluation of model output.
- Args:
- loader:
specifies the source address and the loading operator that can access that source and transform it into a unitxt multistream.
- preprocess_steps:
list of unitxt operators to process the data source into model input.
- task:
specifies the fields (of the already (pre)processed instance) making the inputs, the fields making the outputs, and the metrics to be used for evaluating the model output.
- templates:
format strings to be applied on the input fields (specified by the task) and the output fields. The template also carries the instructions and the list of postprocessing steps, to be applied to the model output.
Explanation about JoinStreamsΒΆ
Join multiple streams into a single stream.
- Args:
left_stream (str): The stream that will be considered the βleftβ in the join operations. right_stream (str): The stream that will be considered the βrightβ in the join operations. how (Literal[βleftβ, βrightβ, βinnerβ, βouterβ, βcrossβ]): The type of join to be performed. on (Optional[List[str]]): Column names to join on. These must be found in both streams. left_on (Optional[List[str]]): Column names to join on in the left stream. right_on (Optional[List[str]]): Column names to join on in the right streasm. new_stream_name (str): The name of the new stream resulting from the merge.
- Examples:
JoinStreams(left_stream = βquestionsβ, right_stream = βanswersβ, how=βinnerβ, on=βquestion_idβ, new_stream_name=βquestion_with_answersβ ) Join the βquestionβ and βanswerβ stream based on the βquestion_idβ field using inner join, resulting with a new stream named βquestion_with_answersβ. JoinStreams(left_stream = βquestionsβ, right_stream = βanswersβ, how=βinnerβ, on_left=βquestion_idβ, on_right=βquestionβ new_stream_name=βquestion_with_answersβ ) Join the βquestionβ and βanswerβ stream based on the βquestion_idβ field in the left stream and the βquestionβ field in the right stream, using inner join, resulting with a new stream named βquestion_with_answersβ. This is suitable when the fields have different labels across the streams.
Explanation about SelectFieldsΒΆ
Keep only specified fields from each instance in a stream.
- Args:
fields (List[str]): The fields to keep from each instance.
Explanation about RenameΒΆ
Renames fields.
Move value from one field to another, potentially, if field name contains a /, from one branch into another. Remove the from field, potentially part of it in case of / in from_field.
- Examples:
Rename(field_to_field={βbβ: βcβ}) will change inputs [{βaβ: 1, βbβ: 2}, {βaβ: 2, βbβ: 3}] to [{βaβ: 1, βcβ: 2}, {βaβ: 2, βcβ: 3}]
Rename(field_to_field={βbβ: βc/dβ}) will change inputs [{βaβ: 1, βbβ: 2}, {βaβ: 2, βbβ: 3}] to [{βaβ: 1, βcβ: {βdβ: 2}}, {βaβ: 2, βcβ: {βdβ: 3}}]
Rename(field_to_field={βbβ: βb/dβ}) will change inputs [{βaβ: 1, βbβ: 2}, {βaβ: 2, βbβ: 3}] to [{βaβ: 1, βbβ: {βdβ: 2}}, {βaβ: 2, βbβ: {βdβ: 3}}]
Rename(field_to_field={βb/c/eβ: βb/dβ}) will change inputs [{βaβ: 1, βbβ: {βcβ: {βeβ: 2, βfβ: 20}}}] to [{βaβ: 1, βbβ: {βcβ: {βfβ: 20}, βdβ: 2}}]
Explanation about CopyΒΆ
Copies values from specified fields to specified fields.
- Args (of parent class):
field_to_field (Union[List[List], Dict[str, str]]): A list of lists, where each sublist contains the source field and the destination field, or a dictionary mapping source fields to destination fields.
- Examples:
An input instance {βaβ: 2, βbβ: 3}, when processed by
Copy(field_to_field={"a": "b"})would yield {βaβ: 2, βbβ: 2}, and when processed byCopy(field_to_field={"a": "c"})would yield {βaβ: 2, βbβ: 3, βcβ: 2}with field names containing / , we can also copy inside the field:
Copy(field="a/0",to_field="a")would process instance {βaβ: [1, 3]} into {βaβ: 1}
Explanation about ApplyΒΆ
A class used to apply a python function and store the result in a field.
- Args:
function (str): name of function. to_field (str): the field to store the result
any additional arguments are field names whose values will be passed directly to the function specified
Examples: Store in field βbβ the uppercase string of the value in field βaβ:
Apply("a", function=str.upper, to_field="b")Dump the json representation of field βtβ and store back in the same field:
Apply("t", function=json.dumps, to_field="t")Set the time in a field βbβ:
Apply(function=time.time, to_field="b")
Explanation about DeleteSplitsΒΆ
Operator which delete splits in stream.
- Attributes:
splits (List[str]): The splits to delete from the stream.
Explanation about SetΒΆ
Sets specified fields in each instance, in a given stream or all streams (default), with specified values. If fields exist, updates them, if do not exist β adds them.
- Args:
fields (Dict[str, object]): The fields to add to each instance. Use β/β to access inner fields
use_deepcopy (bool) : Deep copy the input value to avoid later modifications
- Examples:
# Set a value of a list consisting of βpositiveβ and βnegativeβ do field βclassesβ to each and every instance of all streams
Set(fields={"classes": ["positive","negatives"]})# In each and every instance of all streams, field βspanβ is to become a dictionary containing a field βstartβ, in which the value 0 is to be set
Set(fields={"span/start": 0}# In all instances of stream βtrainβ only, Set field βclassesβ to have the value of a list consisting of βpositiveβ and βnegativeβ
Set(fields={"classes": ["positive","negatives"], apply_to_stream=["train"]})# Set field βclassesβ to have the value of a given list, preventing modification of original list from changing the instance.
Set(fields={"classes": alist}), use_deepcopy=True)if now alist is modified, still the instances remain intact.
Explanation about LoadJsonFileΒΆ
Loads data from JSON files.
Supports streaming and can handle large files by loading them in chunks.
- Args:
files (Dict[str, str]): A dictionary mapping names to file paths. chunksize : Size of the chunks to load at a time. loader_limit: Optional integer to specify a limit on the number of records to load. streaming: Bool indicating if streaming should be used. lines: Bool indicate if it is json lines file structure. Otherwise, assumes a single json object in the file. data_field: optional field within the json object, that contains the list of instances.
- Example:
Loading json lines
load_csv = LoadJsonFile(files={'train': 'path/to/train.jsonl'}, line=True, chunksize=100)
References: templates.generation.empty, tasks.generation
Read more about catalog usage here.