Download python_Code/firstStep-format.py from DagimB/ecfr-textcat: direct link, hf CLI and curl.
- Browser
- Download file 757 Bytes
-
https://huggingface.co/DagimB/ecfr-textcat/resolve/main/python_Code/firstStep-format.py
- Command line
-
hf download hf://DagimB/ecfr-textcat/python_Code/firstStep-format.py
-
curl -L -o firstStep-format.py https://huggingface.co/DagimB/ecfr-textcat/resolve/main/python_Code/firstStep-format.py
757 Bytes
| import jsonlines | |
| # Path to your dataset file | |
| dataset_file = "data/train200.jsonl" | |
| # Path to the output file | |
| output_file = "data/firstStep_file.jsonl" | |
| # Open the JSONL file and extract text and labels | |
| try: | |
| with jsonlines.open(dataset_file) as reader, jsonlines.open(output_file, mode='w') as writer: | |
| for obj in reader: | |
| text = obj.get("text") | |
| label = obj.get("accept", [])[0] # Get the first accepted label if available | |
| if text and label: | |
| writer.write({"text": text, "label": label}) | |
| else: | |
| print("Warning: Text or label missing in the JSON object.") | |
| print("Processing completed. Output written to:", output_file) | |
| except Exception as e: | |
| print("Error:", e) | |