hk-gaianet commited on
Commit
c323378
1 Parent(s): 05c8748

Include pipeline script

Browse files
Files changed (1) hide show
  1. pipeline.py +48 -0
pipeline.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Requirements: `pip install distilabel[hf-inference-endpoints]`
2
+ import os
3
+ import random
4
+ from distilabel.llms import InferenceEndpointsLLM
5
+ from distilabel.pipeline import Pipeline
6
+ from distilabel.steps import LoadDataFromDicts, KeepColumns
7
+ from distilabel.steps.tasks import GenerateTextClassificationData
8
+
9
+ MODEL = "meta-llama/Llama-3.1-8B-Instruct"
10
+ BASE_URL = ""
11
+ TEXT_CLASSIFICATION_TASK = "None"
12
+ os.environ["API_KEY"] = (
13
+ "hf_xxx" # https://huggingface.co/settings/tokens/new?ownUserPermissions=repo.content.read&ownUserPermissions=repo.write&globalPermissions=inference.serverless.write&canReadGatedRepos=true&tokenType=fineGrained
14
+ )
15
+
16
+ with Pipeline(name="textcat") as pipeline:
17
+
18
+ task_generator = LoadDataFromDicts(data=[{"task": TEXT_CLASSIFICATION_TASK}])
19
+
20
+ textcat_generation = GenerateTextClassificationData(
21
+ llm=InferenceEndpointsLLM(
22
+ model_id=MODEL,
23
+ base_url=BASE_URL,
24
+ api_key=os.environ["API_KEY"],
25
+ generation_kwargs={
26
+ "temperature": 0.8,
27
+ "max_new_tokens": 2048,
28
+ "do_sample": True,
29
+ "top_k": 50,
30
+ "top_p": 0.95,
31
+ },
32
+ ),
33
+ seed=random.randint(0, 2**32 - 1),
34
+ difficulty='high school',
35
+ clarity=None,
36
+ num_generations=10,
37
+ output_mappings={"input_text": "text"},
38
+ )
39
+
40
+ keep_columns = KeepColumns(
41
+ columns=["text", "label"],
42
+ )
43
+
44
+ # Connect steps in the pipeline
45
+ task_generator >> textcat_generation >> keep_columns
46
+
47
+ if __name__ == "__main__":
48
+ distiset = pipeline.run()