diff --git a/src/distilabel/steps/tasks/complexity_scorer.py b/src/distilabel/steps/tasks/complexity_scorer.py index 758aaf05d6..b20909383a 100644 --- a/src/distilabel/steps/tasks/complexity_scorer.py +++ b/src/distilabel/steps/tasks/complexity_scorer.py @@ -59,6 +59,32 @@ class ComplexityScorer(Task): References: - [`What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning`](https://arxiv.org/abs/2312.15685) + + Examples: + + Evaluate the complexity of your instructions: + + ```python + from distilabel.steps.tasks import ComplexityScorer + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + scorer = ComplexityScorer( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ) + ) + + scorer.load() + + result = next( + scorer.process( + [{"instructions": ["plain instruction", "highly complex instruction"]}] + ) + ) + # result + # [{'instructions': ['plain instruction', 'highly complex instruction'], 'model_name': 'test', 'scores': [1, 5], 'distilabel_metadata': {'raw_output_complexity_scorer_0': 'output'}}] + ``` """ _template: Union[Template, None] = PrivateAttr(...) diff --git a/src/distilabel/steps/tasks/evol_instruct/base.py b/src/distilabel/steps/tasks/evol_instruct/base.py index b7c4e2f65a..e0071bf5d9 100644 --- a/src/distilabel/steps/tasks/evol_instruct/base.py +++ b/src/distilabel/steps/tasks/evol_instruct/base.py @@ -69,6 +69,86 @@ class EvolInstruct(Task): References: - [WizardLM: Empowering Large Language Models to Follow Complex Instructions](https://arxiv.org/abs/2304.12244) - [GitHub: h2oai/h2o-wizardlm](https://github.com/h2oai/h2o-wizardlm) + + Examples: + + Evolve an instruction using an LLM: + + ```python + from distilabel.steps.tasks import EvolInstruct + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_instruct = EvolInstruct( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_evolutions=2, + ) + + evol_instruct.load() + + result = next(evol_instruct.process([{"instruction": "common instruction"}])) + # result + # [{'instruction': 'common instruction', 'evolved_instruction': 'evolved instruction', 'model_name': 'model_name'}] + ``` + + Keep the iterations of the evolutions: + + ```python + from distilabel.steps.tasks import EvolInstruct + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_instruct = EvolInstruct( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_evolutions=2, + store_evolutions=True, + ) + + evol_instruct.load() + + result = next(evol_instruct.process([{"instruction": "common instruction"}])) + # result + # [ + # { + # 'instruction': 'common instruction', + # 'evolved_instructions': ['initial evolution', 'final evolution'], + # 'model_name': 'model_name' + # } + # ] + ``` + + Generate answers for the instructions in a single step: + + ```python + from distilabel.steps.tasks import EvolInstruct + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_instruct = EvolInstruct( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_evolutions=2, + generate_answers=True, + ) + + evol_instruct.load() + + result = next(evol_instruct.process([{"instruction": "common instruction"}])) + # result + # [ + # { + # 'instruction': 'common instruction', + # 'evolved_instruction': 'evolved instruction', + # 'answer': 'answer to the instruction', + # 'model_name': 'model_name' + # } + # ] + ``` """ num_evolutions: int diff --git a/src/distilabel/steps/tasks/evol_instruct/evol_complexity/base.py b/src/distilabel/steps/tasks/evol_instruct/evol_complexity/base.py index 75161eb70c..c07f49d621 100644 --- a/src/distilabel/steps/tasks/evol_instruct/evol_complexity/base.py +++ b/src/distilabel/steps/tasks/evol_instruct/evol_complexity/base.py @@ -24,7 +24,7 @@ class EvolComplexity(EvolInstruct): """Evolve instructions to make them more complex using an `LLM`. `EvolComplexity` is a task that evolves instructions to make them more complex, - and it is based in the EvolInstruct task, but using slight different prompts, but the + and it is based in the EvolInstruct task, using slight different prompts, but the exact same evolutionary approach. Attributes: @@ -61,6 +61,29 @@ class EvolComplexity(EvolInstruct): References: - [What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning](https://arxiv.org/abs/2312.15685) - [WizardLM: Empowering Large Language Models to Follow Complex Instructions](https://arxiv.org/abs/2304.12244) + + Examples: + + Evolve an instruction using an LLM: + + ```python + from distilabel.steps.tasks import EvolComplexity + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_complexity = EvolComplexity( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_evolutions=2, + ) + + evol_complexity.load() + + result = next(evol_complexity.process([{"instruction": "common instruction"}])) + # result + # [{'instruction': 'common instruction', 'evolved_instruction': 'evolved instruction', 'model_name': 'model_name'}] + ``` """ mutation_templates: Dict[str, str] = MUTATION_TEMPLATES diff --git a/src/distilabel/steps/tasks/evol_instruct/evol_complexity/generator.py b/src/distilabel/steps/tasks/evol_instruct/evol_complexity/generator.py index 8fc1f35db8..c4cd051190 100644 --- a/src/distilabel/steps/tasks/evol_instruct/evol_complexity/generator.py +++ b/src/distilabel/steps/tasks/evol_instruct/evol_complexity/generator.py @@ -59,6 +59,29 @@ class EvolComplexityGenerator(EvolInstructGenerator): References: - [What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning](https://arxiv.org/abs/2312.15685) - [WizardLM: Empowering Large Language Models to Follow Complex Instructions](https://arxiv.org/abs/2304.12244) + + Examples: + + Generate evolved instructions without initial instructions: + + ```python + from distilabel.steps.tasks import EvolComplexityGenerator + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_complexity_generator = EvolComplexityGenerator( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_instructions=2, + ) + + evol_complexity_generator.load() + + result = next(scorer.process()) + # result + # [{'instruction': 'generated instruction', 'model_name': 'test'}] + ``` """ mutation_templates: Dict[str, str] = GENERATION_MUTATION_TEMPLATES diff --git a/src/distilabel/steps/tasks/evol_instruct/generator.py b/src/distilabel/steps/tasks/evol_instruct/generator.py index 8d4adc38b5..bc8c5d2eff 100644 --- a/src/distilabel/steps/tasks/evol_instruct/generator.py +++ b/src/distilabel/steps/tasks/evol_instruct/generator.py @@ -75,6 +75,29 @@ class EvolInstructGenerator(GeneratorTask): References: - [WizardLM: Empowering Large Language Models to Follow Complex Instructions](https://arxiv.org/abs/2304.12244) - [GitHub: h2oai/h2o-wizardlm](https://github.com/h2oai/h2o-wizardlm) + + Examples: + + Generate evolved instructions without initial instructions: + + ```python + from distilabel.steps.tasks import EvolInstructGenerator + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_instruct_generator = EvolInstructGenerator( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_instructions=2, + ) + + evol_instruct_generator.load() + + result = next(scorer.process()) + # result + # [{'instruction': 'generated instruction', 'model_name': 'test'}] + ``` """ num_instructions: int diff --git a/src/distilabel/steps/tasks/evol_quality/base.py b/src/distilabel/steps/tasks/evol_quality/base.py index 0b50e568cc..b245a879ff 100644 --- a/src/distilabel/steps/tasks/evol_quality/base.py +++ b/src/distilabel/steps/tasks/evol_quality/base.py @@ -65,6 +65,42 @@ class EvolQuality(Task): References: - [`What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning`](https://arxiv.org/abs/2312.15685) + + Examples: + + Evolve the quality of the responses given a prompt: + + ```python + from distilabel.steps.tasks import EvolQuality + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + evol_quality = EvolQuality( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_evolutions=2, + ) + + evol_quality.load() + + result = next( + evol_quality.process( + [ + {"instruction": "common instruction", "response": "a response"}, + ] + ) + ) + # result + # [ + # { + # 'instruction': 'common instruction', + # 'response': 'a response', + # 'evolved_response': 'evolved response', + # 'model_name': '"mistralai/Mistral-7B-Instruct-v0.2"' + # } + # ] + ``` """ num_evolutions: int diff --git a/src/distilabel/steps/tasks/generate_embeddings.py b/src/distilabel/steps/tasks/generate_embeddings.py index 39c17f016e..1b0df634c6 100644 --- a/src/distilabel/steps/tasks/generate_embeddings.py +++ b/src/distilabel/steps/tasks/generate_embeddings.py @@ -47,6 +47,33 @@ class GenerateEmbeddings(Step): References: - [What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning](https://arxiv.org/abs/2312.15685) + + Examples: + + Rank LLM candidates: + + ```python + from distilabel.steps.tasks import GenerateEmbeddings + from distilabel.llms.huggingface import TransformersLLM + + # Consider this as a placeholder for your actual LLM. + embedder = GenerateEmbeddings( + llm=TransformersLLM( + model="TaylorAI/bge-micro-v2", + model_kwargs={"is_decoder": True}, + cuda_devices=[], + ) + ) + embedder.load() + + result = next( + embedder.process( + [ + {"text": "Hello, how are you?"}, + ] + ) + ) + ``` """ llm: LLM diff --git a/src/distilabel/steps/tasks/genstruct.py b/src/distilabel/steps/tasks/genstruct.py index 550e1220d5..1e80fcb429 100644 --- a/src/distilabel/steps/tasks/genstruct.py +++ b/src/distilabel/steps/tasks/genstruct.py @@ -67,6 +67,42 @@ class Genstruct(Task): References: - [Genstruct 7B by Nous Research](https://huggingface.co/NousResearch/Genstruct-7B) - [Ada-Instruct: Adapting Instruction Generators for Complex Reasoning](https://arxiv.org/abs/2310.04484) + + Examples: + + Generate instructions from raw documents using the title and content: + + ```python + from distilabel.steps.tasks import Genstruct + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + genstruct = Genstruct( + llm=InferenceEndpointsLLM( + model_id="NousResearch/Genstruct-7B", + ), + ) + + genstruct.load() + + result = next( + genstruct.process( + [ + {"title": "common instruction", "content": "content of the document"}, + ] + ) + ) + # result + # [ + # { + # 'title': 'An instruction', + # 'content': 'content of the document', + # 'model_name': 'test', + # 'user': 'An instruction', + # 'assistant': 'content of the document', + # } + # ] + ``` """ _template: Union[Template, None] = PrivateAttr(...) diff --git a/src/distilabel/steps/tasks/pair_rm.py b/src/distilabel/steps/tasks/pair_rm.py index 3c1ecc7a56..be23a38699 100644 --- a/src/distilabel/steps/tasks/pair_rm.py +++ b/src/distilabel/steps/tasks/pair_rm.py @@ -49,6 +49,37 @@ class PairRM(Step): Note: This step differs to other tasks as there is a single implementation of this model currently, and we will use a specific `LLM`. + + Examples: + + Rank LLM candidates: + + ```python + from distilabel.steps.tasks import PairRM + + # Consider this as a placeholder for your actual LLM. + pair_rm = PairRM() + + pair_rm.load() + + result = next( + scorer.process( + [ + {"input": "Hello, how are you?", "candidates": ["fine", "good", "bad"]}, + ] + ) + ) + # result + # [ + # { + # 'input': 'Hello, how are you?', + # 'candidates': ['fine', 'good', 'bad'], + # 'ranks': [2, 1, 3], + # 'ranked_candidates': ['good', 'fine', 'bad'], + # 'model_name': 'llm-blender/PairRM', + # } + # ] + ``` """ model: str = "llm-blender/PairRM" diff --git a/src/distilabel/steps/tasks/prometheus_eval.py b/src/distilabel/steps/tasks/prometheus_eval.py index 0edde308df..4b03c3932f 100644 --- a/src/distilabel/steps/tasks/prometheus_eval.py +++ b/src/distilabel/steps/tasks/prometheus_eval.py @@ -135,6 +135,165 @@ class PrometheusEval(Task): References: - [Prometheus 2: An Open Source Language Model Specialized in Evaluating Other Language Models](https://arxiv.org/abs/2405.01535) - [prometheus-eval: Evaluate your LLM's response with Prometheus 💯](https://github.com/prometheus-eval/prometheus-eval) + + Examples: + + Critique and evaluate LLM generation quality using Prometheus 2.0: + + ```python + from distilabel.steps.tasks import PrometheusEval + from distilabel.llms import vLLM + + # Consider this as a placeholder for your actual LLM. + prometheus = PrometheusEval( + llm=vLLM( + model="prometheus-eval/prometheus-7b-v2.0", + chat_template="[INST] {{ messages[0]['content'] }}\n{{ messages[1]['content'] }}[/INST]", + ), + mode="absolute", + rubric="factual-validity" + ) + + prometheus.load() + + result = next( + prometheus.process( + [ + {"instruction": "make something", "generation": "something done"}, + ] + ) + ) + # result + # [ + # { + # 'instruction': 'make something', + # 'generation': 'something done', + # 'model_name': 'prometheus-eval/prometheus-7b-v2.0', + # 'feedback': 'the feedback', + # 'result': 6, + # } + # ] + ``` + + Critique for relative evaluation: + + ```python + from distilabel.steps.tasks import PrometheusEval + from distilabel.llms import vLLM + + # Consider this as a placeholder for your actual LLM. + prometheus = PrometheusEval( + llm=vLLM( + model="prometheus-eval/prometheus-7b-v2.0", + chat_template="[INST] {{ messages[0]['content'] }}\n{{ messages[1]['content'] }}[/INST]", + ), + mode="relative", + rubric="honesty" + ) + + prometheus.load() + + result = next( + prometheus.process( + [ + {"instruction": "make something", "generations": ["something done", "other thing"]}, + ] + ) + ) + # result + # [ + # { + # 'instruction': 'make something', + # 'generations': ['something done', 'other thing'], + # 'model_name': 'prometheus-eval/prometheus-7b-v2.0', + # 'feedback': 'the feedback', + # 'result': 'something done', + # } + # ] + ``` + + Critique with a custom rubric: + + ```python + from distilabel.steps.tasks import PrometheusEval + from distilabel.llms import vLLM + + # Consider this as a placeholder for your actual LLM. + prometheus = PrometheusEval( + llm=vLLM( + model="prometheus-eval/prometheus-7b-v2.0", + chat_template="[INST] {{ messages[0]['content'] }}\n{{ messages[1]['content'] }}[/INST]", + ), + mode="absolute", + rubric="custom", + rubrics={ + "custom": "[A]\nScore 1: A\nScore 2: B\nScore 3: C\nScore 4: D\nScore 5: E" + } + ) + + prometheus.load() + + result = next( + prometheus.process( + [ + {"instruction": "make something", "generation": "something done"}, + ] + ) + ) + # result + # [ + # { + # 'instruction': 'make something', + # 'generation': 'something done', + # 'model_name': 'prometheus-eval/prometheus-7b-v2.0', + # 'feedback': 'the feedback', + # 'result': 6, + # } + # ] + ``` + + Critique using a reference answer: + + ```python + from distilabel.steps.tasks import PrometheusEval + from distilabel.llms import vLLM + + # Consider this as a placeholder for your actual LLM. + prometheus = PrometheusEval( + llm=vLLM( + model="prometheus-eval/prometheus-7b-v2.0", + chat_template="[INST] {{ messages[0]['content'] }}\n{{ messages[1]['content'] }}[/INST]", + ), + mode="absolute", + rubric="helpfulness", + reference=True, + ) + + prometheus.load() + + result = next( + prometheus.process( + [ + { + "instruction": "make something", + "generation": "something done", + "reference": "this is a reference answer", + }, + ] + ) + ) + # result + # [ + # { + # 'instruction': 'make something', + # 'generation': 'something done', + # 'reference': 'this is a reference answer', + # 'model_name': 'prometheus-eval/prometheus-7b-v2.0', + # 'feedback': 'the feedback', + # 'result': 6, + # } + # ] + ``` """ mode: Literal["absolute", "relative"] @@ -202,7 +361,7 @@ def inputs(self) -> List[str]: if self.reference: return ["instruction", "generation", "reference"] return ["instruction", "generation"] - else: # self.mode == "relative" + else: if self.reference: return ["instruction", "generations", "reference"] return ["instruction", "generations"] diff --git a/src/distilabel/steps/tasks/quality_scorer.py b/src/distilabel/steps/tasks/quality_scorer.py index f805c91e38..a93c2a399a 100644 --- a/src/distilabel/steps/tasks/quality_scorer.py +++ b/src/distilabel/steps/tasks/quality_scorer.py @@ -59,6 +59,43 @@ class QualityScorer(Task): References: - [`What Makes Good Data for Alignment? A Comprehensive Study of Automatic Data Selection in Instruction Tuning`](https://arxiv.org/abs/2312.15685) + + Examples: + + Evaluate the quality of your instructions: + + ```python + from distilabel.steps.tasks import QualityScorer + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + scorer = QualityScorer( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ) + ) + + scorer.load() + + result = next( + scorer.process( + [ + { + "instruction": "instruction", + "responses": ["good response", "weird response", "bad response"] + } + ] + ) + ) + # result + [ + { + 'instructions': 'instruction', + 'model_name': 'test', + 'scores': [5, 3, 1], + } + ] + ``` """ _template: Union[Template, None] = PrivateAttr(...) diff --git a/src/distilabel/steps/tasks/self_instruct.py b/src/distilabel/steps/tasks/self_instruct.py index 6bb673b8cf..34d3ffee06 100644 --- a/src/distilabel/steps/tasks/self_instruct.py +++ b/src/distilabel/steps/tasks/self_instruct.py @@ -60,6 +60,34 @@ class SelfInstruct(Task): Reference: - [`Self-Instruct: Aligning Language Models with Self-Generated Instructions`](https://arxiv.org/abs/2212.10560) + + Examples: + + Generate instructions based on a given input: + + ```python + from distilabel.steps.tasks import SelfInstruct + from distilabel.llms.huggingface import InferenceEndpointsLLM + + self_instruct = SelfInstruct( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ), + num_instructions=5, # This is the default value + ) + + self_instruct.load() + + result = next(self_instruct.process([{"input": "instruction"}])) + # result + # [ + # { + # 'input': 'instruction', + # 'model_name': 'mistralai/Mistral-7B-Instruct-v0.2', + # 'instructions': ["instruction 1", "instruction 2", "instruction 3", "instruction 4", "instruction 5"], + # } + # ] + ``` """ num_instructions: int = 5 diff --git a/src/distilabel/steps/tasks/structured_generation.py b/src/distilabel/steps/tasks/structured_generation.py index ca43f9beba..6171c0bc83 100644 --- a/src/distilabel/steps/tasks/structured_generation.py +++ b/src/distilabel/steps/tasks/structured_generation.py @@ -47,10 +47,93 @@ class StructuredGeneration(Task): - structured-generation Examples: + + Generate structured output from a JSON schema: + ```python from distilabel.steps.tasks import StructuredGeneration + from distilabel.llms import InferenceEndpointsLLM + + structured_gen = StructuredGeneration( + llm=InferenceEndpointsLLM( + model_id="meta-llama/Meta-Llama-3-70B-Instruct", + tokenizer_id="meta-llama/Meta-Llama-3-70B-Instruct", + ), + ) + + structured_gen.load() + + result = next( + structured_gen.process( + [ + { + "instruction": "Create an RPG character", + "structured_output": { + "type": "json", + "value": { + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "role": { + "title": "Role", + "type": "string" + }, + "weapon": { + "title": "Weapon", + "type": "string" + } + }, + "required": [ + "name", + "description", + "role", + "weapon" + ], + "title": "Character", + "type": "object" + } + }, + } + ] + ) + ) + ``` - task = StructuredGeneration(llm=LLM(...)) + Generate structured output from a regex pattern: + + ```python + from distilabel.steps.tasks import StructuredGeneration + from distilabel.llms import InferenceEndpointsLLM + + structured_gen = StructuredGeneration( + llm=InferenceEndpointsLLM( + model_id="meta-llama/Meta-Llama-3-70B-Instruct", + tokenizer_id="meta-llama/Meta-Llama-3-70B-Instruct", + ), + ) + + structured_gen.load() + + result = next( + structured_gen.process( + [ + { + "instruction": "What's the weather like today in Seattle in Celsius degrees?", + "structured_output": { + "type": "regex", + "value": r"(\\d{1,2})°C" + }, + + } + ] + ) + ) ``` """ diff --git a/src/distilabel/steps/tasks/text_generation.py b/src/distilabel/steps/tasks/text_generation.py index 3a3166b447..3f5b17a8fb 100644 --- a/src/distilabel/steps/tasks/text_generation.py +++ b/src/distilabel/steps/tasks/text_generation.py @@ -43,10 +43,35 @@ class TextGeneration(Task): - text-generation Examples: + + Generate text from an instruction: + ```python from distilabel.steps.tasks import TextGeneration + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + text_gen = TextGeneration( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ) + ) - task = TextGeneration(llm=LLM(...)) + text_gen.load() + + result = next( + text_gen.process( + [{"instruction": "your instruction"}] + ) + ) + # result + # [ + # { + # 'instruction': 'your instruction', + # 'model_name': 'mistralai/Mistral-7B-Instruct-v0.2', + # 'generation': 'generation', + # } + # ] ``` """ @@ -119,6 +144,44 @@ class ChatGeneration(Task): Icon: `:material-chat:` + + Examples: + + Generate text from a conversation in OpenAI chat format: + + ```python + from distilabel.steps.tasks import ChatGeneration + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + chat = ChatGeneration( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ) + ) + + chat.load() + + result = next( + chat.process( + [ + { + "messages": [ + {"role": "user", "content": "How much is 2+2?"}, + ] + } + ] + ) + ) + # result + # [ + # { + # 'messages': [{'role': 'user', 'content': 'How much is 2+2?'}], + # 'model_name': 'mistralai/Mistral-7B-Instruct-v0.2', + # 'generation': '4', + # } + # ] + ``` """ @property diff --git a/src/distilabel/steps/tasks/ultrafeedback.py b/src/distilabel/steps/tasks/ultrafeedback.py index 9b200ddafd..c6cd95482c 100644 --- a/src/distilabel/steps/tasks/ultrafeedback.py +++ b/src/distilabel/steps/tasks/ultrafeedback.py @@ -60,6 +60,45 @@ class UltraFeedback(Task): References: - [`UltraFeedback: Boosting Language Models with High-quality Feedback`](https://arxiv.org/abs/2310.01377) - [`UltraFeedback - GitHub Repository`](https://github.com/OpenBMB/UltraFeedback) + + Examples: + + Rate generations from different LLMs based on the selected aspect: + + ```python + from distilabel.steps.tasks import UltraFeedback + from distilabel.llms.huggingface import InferenceEndpointsLLM + + # Consider this as a placeholder for your actual LLM. + ultrafeedback = UltraFeedback( + llm=InferenceEndpointsLLM( + model_id="mistralai/Mistral-7B-Instruct-v0.2", + ) + ) + + ultrafeedback.load() + + result = next( + chat.process( + [ + { + "instruction": "How much is 2+2?", + "generations": ["4", "and a car"], + } + ] + ) + ) + # result + # [ + # { + # 'instruction': 'How much is 2+2?', + # 'generations': ['4', 'and a car'], + # 'ratings': [1, 2], + # 'rationales': ['explanation for 4', 'explanation for and a car'], + # 'model_name': 'mistralai/Mistral-7B-Instruct-v0.2', + # } + # ] + ``` """ aspect: Literal[