πŸ“„ English Gpt 4 0314 ReferenceΒΆ

cards.arena_hard.generation.english_gpt_4_0314_reference

type: TaskCard
loader: 
  type: LoadFromHFSpace
  space_name: lmsys/arena-hard-browser
  revision: 03b91ca
  data_files: 
    questions: data/arena-hard-v0.1/question.jsonl
    model_answer: data/arena-hard-v0.1/model_answer/gpt-4-0314.jsonl
preprocess_steps: 
  - type: Rename
    field_to_field: 
      cluster: group
    apply_to_streams: 
      - questions
  - type: Copy
    field_to_field: 
      turns/0/content: model_input
    apply_to_streams: 
      - questions
  - type: Set
    fields: 
      reference_model: gpt-4-0314
    apply_to_streams: 
      - questions
  - type: Copy
    field_to_field: 
      choices/0/turns/0/content: reference_model_output
      choices/0/turns/0/token_len: reference_model_output_token_len
    apply_to_streams: 
      - model_answer
  - type: Rename
    field_to_field: 
      model_id: reference_model
    apply_to_streams: 
      - model_answer
  - type: Apply
    function: str.lower
    to_field: reference_model
    apply_to_streams: 
      - model_answer
    _argv: 
      - reference_model
  - type: JoinStreams
    left_stream: questions
    right_stream: model_answer
    how: inner
    on: 
      - question_id
      - reference_model
    new_stream_name: test
  - type: DeleteSplits
    splits: 
      - questions
      - model_answer
  - type: SelectFields
    fields: 
      - question_id
      - category
      - model_input
      - reference_model
      - reference_model_output
  - type: Rename
    field_to_field: 
      model_input: input
      category: group
      reference_model_output: output
  - type: Set
    fields: 
      type_of_input: prompt
      type_of_output: answer
task: tasks.generation
templates: 
  - templates.generation.empty
[source]

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.

default_template:

a default template for tasks with very specific task dataset specific template

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 by Copy(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 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 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 LoadFromHFSpaceΒΆ

Used to load data from HuggingFace Spaces.

Loaders firstly tries to download all files specified in the β€˜data_files’ parameter from the given space and then reads them as a HuggingFace Dataset.

Args:
space_name (str):

Name of the HuggingFace Space to be accessed.

data_files (str | Sequence[str] | Mapping[str, str | Sequence[str]]):

Relative paths to files within a given repository. If given as a mapping, paths should be values, while keys should represent the type of respective files (training, testing etc.).

path (str, optional):

Absolute path to a directory where data should be downloaded.

revision (str, optional):

ID of a Git branch or commit to be used. By default, it is set to None, thus data is downloaded from the main branch of the accessed repository.

use_token (bool, optional):

Whether a token is used for authentication when accessing the HuggingFace Space. If necessary, the token is read from the HuggingFace config folder.

token_env (str, optional):

Key of an env variable which value will be used for authentication when accessing the HuggingFace Space - if necessary.

Example:

Loading from a HuggingFace Space

loader = LoadFromHFSpace(
    space_name="lmsys/mt-bench",
    data_files={
        "train": [
            "data/mt_bench/model_answer/gpt-3.5-turbo.jsonl",
            "data/mt_bench/model_answer/gpt-4.jsonl",
        ],
        "test": "data/mt_bench/model_answer/tulu-30b.jsonl",
    },
)

Explanation about DeleteSplitsΒΆ

Operator which delete splits in stream.

Attributes:

splits (List[str]): The splits to delete from the stream.

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 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 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")

References: templates.generation.empty, tasks.generation

Read more about catalog usage here.