Skip to content

Commit 8f3c446

Browse files
authored
Documenation updates (#1790)
* Documentation updates * More doc changes * Update docs/docs/examples.rst Fixed link
1 parent 4244721 commit 8f3c446

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

docs/docs/examples.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ This example demonstrates how to evaluate model tool calling capabilities. It r
9090
a set of user textual requests and corresponding reference answers as tool calls.
9191
The model is expected to generate tool calls and these are compared to the references.
9292

93-
`Example code <https://github.com/IBM/unitxt/blob/main/examples/tool_call_evaluation.py>`__
93+
`Example code <https://github.com/IBM/unitxt/blob/main/examples/evaluate_tool_calling.py>`__
9494

95-
Related documentation: :ref:`Tool calling task in catalog <catalog.tasks.tool_calling.supervised>`,:ref:`Tool calling tutorial <tool_calling>`,
95+
Related documentation: :ref:`Tool calling task in catalog <catalog.tasks.tool_calling.supervised>`, :ref:`Tool calling tutorial <tool_calling>`
9696

9797

9898
Evaluate API Call
@@ -106,7 +106,7 @@ using the standard key_value_extraction metric.
106106

107107
`Example code <https://github.com/IBM/unitxt/blob/main/examples/api_call_evaluation.py>`__
108108

109-
Related documentation: :ref:`Key Value Extraction metric in catalog <catalog.metrics.key_value_extraction>`,:ref:`Templates tutorial <adding_template>`,
109+
Related documentation: :ref:`Key Value Extraction metric in catalog <catalog.metrics.key_value_extraction>`, :ref:`Templates tutorial <adding_template>`
110110

111111
Evaluate using Unitxt metrics on existing predictions
112112
+++++++++++++++++++++++++++++++++++++++++++++++++++++++

src/unitxt/operators.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,21 @@ def recursive_key_value_replace(data, target_key, value_map, value_remove=None):
324324
return data
325325

326326
class RecursiveReplace(InstanceOperator):
327+
# Assisted by watsonx Code Assistant
328+
"""An operator to recursively replace values in dictionary fields of instances based on a key and a mapping of values.
329+
330+
Attributes:
331+
key (str): The key in the dictionary to start the replacement process.
332+
map_values (dict): A dictionary containing the key-value pairs to replace the original values.
333+
remove_values (Optional[list]): An optional list of values to remove from the dictionary. Defaults to None.
334+
335+
Example:
336+
RecursiveReplace(key="a", map_values={"1": "hi", "2": "bye" }, remove_values=["3"])
337+
replaces the value of key "a" in all instances of all streams:
338+
instance ``{"field" : [{"a": "1", "b" : "2"}, {"a" : "3", "b:" "4"}}` becomes ``{"field" : [{"a": "hi", "b" : "2"}, {"b": "4"}}``
339+
340+
Notice how the value of field ``"a"`` in the first instance is replaced with ``"hi"`` and the value of field ``"a"`` in the second instance is removed.
341+
"""
327342
key: str
328343
map_values: dict
329344
remove_values: Optional[list] = None
@@ -605,10 +620,27 @@ class AddConstant(FieldOperator):
605620
def process_value(self, value: Any) -> Any:
606621
return self.add + value
607622

608-
609623
class ShuffleFieldValues(FieldOperator):
610-
"""Shuffles a list of values found in a field."""
624+
# Assisted by watsonx Code Assistant
625+
"""An operator that shuffles the values of a list field.
626+
627+
the seed for shuffling in the is determined by the elements of the input field,
628+
ensuring that the shuffling operation produces different results for different input lists,
629+
but also that it is deterministic and reproducible.
630+
631+
Attributes:
632+
None
611633
634+
Methods:
635+
process_value(value: Any) -> Any:
636+
Shuffles the elements of the input list and returns the shuffled list.
637+
638+
Parameters:
639+
value (Any): The input list to be shuffled.
640+
641+
Returns:
642+
Any: The shuffled list.
643+
"""
612644
def process_value(self, value: Any) -> Any:
613645
res = list(value)
614646
random_generator = new_random_generator(sub_seed=res)
@@ -945,7 +977,14 @@ class CopyFields(Copy):
945977

946978

947979
class GetItemByIndex(FieldOperator):
948-
"""Get from the item list by the index in the field."""
980+
"""Get the element from the fixed list by the index in the given field and store in another field.
981+
982+
Example:
983+
GetItemByIndex(items_list=["dog",cat"],field="animal_index",to_field="animal")
984+
985+
on instance {"animal_index" : 1} will change the instance to {"animal_index" : 1, "animal" : "cat"}
986+
987+
"""
949988

950989
items_list: List[Any]
951990

0 commit comments

Comments
 (0)