Daniel Vila commited on
Commit
a7d1c2d
0 Parent(s):

Duplicate from dvilasuero/alpaca-cleaned-de

Browse files
Files changed (4) hide show
  1. .gitattributes +34 -0
  2. Dockerfile +7 -0
  3. README.md +13 -0
  4. load_data.py +105 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM argilla/argilla-quickstart:latest
2
+
3
+ COPY load_data.py /
4
+
5
+ RUN pip install argilla[listeners]
6
+
7
+ CMD whoami && /start_quickstart_argilla.sh
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Alpaca Dataset Validation with Argilla
3
+ emoji: 🦙 🏷️
4
+ colorFrom: purple
5
+ colorTo: red
6
+ sdk: docker
7
+ app_port: 6900
8
+ fullWidth: true
9
+ tags:
10
+ - argilla
11
+ - somosnlp
12
+ duplicated_from: dvilasuero/alpaca-cleaned-de
13
+ ---
load_data.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import time
3
+ import os
4
+
5
+ import argilla as rg
6
+ import pandas as pd
7
+ import requests
8
+ from datasets import load_dataset, concatenate_datasets
9
+
10
+ from argilla.listeners import listener
11
+
12
+ HF_TOKEN = os.environ.get("HF_TOKEN")
13
+ SOURCE_DATASET = "LEL-A/translated_german_alpaca"
14
+ RG_DATASET_NAME = "translated-german-alpaca"
15
+ HUB_DATASET_NAME = os.environ.get('HUB_DATASET_NAME', f"{SOURCE_DATASET}_validation")
16
+
17
+ @listener(
18
+ dataset=RG_DATASET_NAME,
19
+ query="status:Validated", # https://docs.argilla.io/en/latest/guides/features/queries.html
20
+ execution_interval_in_seconds=1200, # interval to check the execution of `save_validated_to_hub`
21
+ )
22
+ def save_validated_to_hub(records, ctx):
23
+ if len(records) > 0:
24
+ ds = rg.DatasetForTextClassification(records=records).to_datasets()
25
+ if HF_TOKEN:
26
+ print("Pushing the dataset")
27
+ print(ds)
28
+ ds.push_to_hub(HUB_DATASET_NAME, token=HF_TOKEN)
29
+ else:
30
+ print("SET HF_TOKEN and HUB_DATASET_NAME TO SYNC YOUR DATASET!!!")
31
+ else:
32
+ print("NO RECORDS found")
33
+
34
+ class LoadDatasets:
35
+ def __init__(self, api_key, workspace="team"):
36
+ rg.init(api_key=api_key, workspace=workspace)
37
+
38
+ @staticmethod
39
+ def load_somos():
40
+ # Leer el dataset del Hub
41
+ try:
42
+ print(f"Trying to sync with {HUB_DATASET_NAME}")
43
+ old_ds = load_dataset(HUB_DATASET_NAME, split="train")
44
+ except Exception as e:
45
+ print(f"Not possible to sync with {HUB_DATASET_NAME}")
46
+ print(e)
47
+ old_ds = None
48
+
49
+ print(f"Loading dataset: {SOURCE_DATASET}")
50
+ dataset = load_dataset(SOURCE_DATASET, split="train")
51
+
52
+
53
+ if old_ds:
54
+ print("Concatenating datasets")
55
+ dataset = concatenate_datasets([dataset, old_ds])
56
+ print("Concatenated dataset is:")
57
+ print(dataset)
58
+
59
+ dataset = dataset.remove_columns("metrics")
60
+ records = rg.DatasetForTextClassification.from_datasets(dataset)
61
+
62
+ settings = rg.TextClassificationSettings(
63
+ label_schema=["BAD INSTRUCTION", "BAD INPUT", "BAD OUTPUT", "INAPPROPRIATE", "BIASED", "ALL GOOD"]
64
+ )
65
+
66
+ print(f"Configuring dataset: {RG_DATASET_NAME}")
67
+ rg.configure_dataset(name=RG_DATASET_NAME, settings=settings, workspace="team")
68
+
69
+ # Log the dataset
70
+ print(f"Logging dataset: {RG_DATASET_NAME}")
71
+ rg.log(
72
+ records,
73
+ name=RG_DATASET_NAME,
74
+ tags={"description": "Alpaca dataset to clean up"},
75
+ batch_size=200
76
+ )
77
+
78
+ # run listener
79
+ save_validated_to_hub.start()
80
+
81
+ if __name__ == "__main__":
82
+ API_KEY = sys.argv[1]
83
+ LOAD_DATASETS = sys.argv[2]
84
+
85
+ if LOAD_DATASETS.lower() == "none":
86
+ print("No datasets being loaded")
87
+ else:
88
+ while True:
89
+ try:
90
+ response = requests.get("http://0.0.0.0:6900/")
91
+ if response.status_code == 200:
92
+ ld = LoadDatasets(API_KEY)
93
+ ld.load_somos()
94
+ break
95
+
96
+ except requests.exceptions.ConnectionError:
97
+ pass
98
+ except Exception as e:
99
+ print(e)
100
+ time.sleep(10)
101
+ pass
102
+
103
+ time.sleep(5)
104
+ while True:
105
+ time.sleep(60)