Download clean.py from gesh75/netops-intent2cli: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/datasets/gesh75/netops-intent2cli/resolve/main/clean.py
- Command line
-
hf download hf://datasets/gesh75/netops-intent2cli/clean.py
-
curl -L -o clean.py https://huggingface.co/datasets/gesh75/netops-intent2cli/resolve/main/clean.py
1.05 kB
| import json,re,collections,difflib | |
| def norm_cmd(c): | |
| c=re.sub(r'^\[[^\]]+\]\s*','',c); c=c.replace('\\"','"'); return c.strip() | |
| def tmpl(s): return re.sub(r'\d+','N',s.lower()) | |
| stats=collections.Counter() | |
| for sp in ['train','val','test']: | |
| rows=[json.loads(l) for l in open(f'train/intent_v1/{sp}.jsonl')] | |
| out=[];seen=set() | |
| for r in rows: | |
| c=norm_cmd(r['command']) | |
| if c!=r['command']: stats['cmd_normalized']+=1 | |
| r['command_original']=r['command']; r['command']=c | |
| it=r['intent'].strip() | |
| # restate: intent tokens mostly == command tokens | |
| ct=set(re.findall(r'[a-z0-9]+',c.lower())); itok=re.findall(r'[a-z0-9]+',it.lower()) | |
| if difflib.SequenceMatcher(None,it.lower(),c.lower()).ratio()>0.85 or (itok and all(t in ct for t in itok)): | |
| stats['restate']+=1;continue | |
| k=(r['vendor'],tmpl(c)) | |
| if k in seen: stats['templated_dup']+=1;continue | |
| seen.add(k); out.append(r) | |
| with open(f'train/intent_v1.1/{sp}.jsonl','w') as f: | |
| for r in out: f.write(json.dumps(r)+'\n') | |
| stats[sp]=len(out) | |
| print(dict(stats)) | |