Views
No views yet
CS221DoAn/Do_an_group_CRF is a machine learning model based on Conditional Random Fields (CRF). It is specifically trained for Named Entity Recognition (NER) on domain-specific Vietnamese unstructured text: Online Food Delivery Orders and Messages.seqeval framework.0.9889O to I-FOOD is exactly 0).huggingface_hub and sklearn-crfsuite libraries.1pip install huggingface_hub sklearn-crfsuite
2⚠️ IMPORTANT: You MUST replace theword2featuresfunction below with the exact feature extraction function you used during the training phase. Otherwise, the model will not understand the input data format.
1import pickle
2from huggingface_hub import hf_hub_download
3
4# 1. Download and load the .pkl model from Hugging Face Hub
5REPO_ID = "CS221DoAn/Do_an_group_CRF"
6FILENAME = "crf_model.pkl"
7
8print("Downloading and loading the CRF model...")
9model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
10
11with open(model_path, "rb") as f:
12 crf_model = pickle.load(f)
13
14# 2. Define the Feature Extraction Function (MUST MATCH YOUR TRAINING CODE)
15def word2features(sent, i):
16 word = sent[i]
17 # --- REPLACE THIS BLOCK WITH YOUR ACTUAL FEATURE ENGINEERING LOGIC ---
18 features = {
19 'bias': 1.0,
20 'word.lower()': word.lower(),
21 'word.isupper()': word.isupper(),
22 'word.istitle()': word.istitle(),
23 'word.isdigit()': word.isdigit(),
24 'word[:2]': word[:2] if len(word) > 2 else word,
25 'word[-2:]': word[-2:] if len(word) > 2 else word,
26 }
27 # ---------------------------------------------------------------------
28 return features
29
30def sent2features(sent):
31 return [word2features(sent, i) for i in range(len(sent))]
32
33# 3. Predict Function
34def predict_food_order(raw_text):
35 print(f"\nInput: {raw_text}")
36 print("=" * 60)
37
38 # Simple whitespace tokenization (Replace with VnCoreNLP if you used it during training)
39 tokens = raw_text.split()
40
41 # Extract features
42 features = [sent2features(tokens)]
43
44 # Predict
45 preds = crf_model.predict(features)[0]
46
47 # Display Extracted Entities
48 for token, label in zip(tokens, preds):
49 print(f"{token:<20} {label}")
50
51# --- EXECUTE TEST CASES ---
52test_cases = [
53 "1p cải xào, gà lát chiên giòn, chả giò, cơm thêm",
54 "giao rào b4, 11h30. 0773570xxx."
55]
56
57for sample in test_cases:
58 predict_food_order(sample)
591@misc{cs221_food_order_ner_crf,
2 author = {Vo Thanh Loc and Nguyen Anh Nguyen},
3 title = {Food Order Extraction: Conditional Random Fields Baseline for Vietnamese NER},
4 year = {2026},
5 publisher = {Hugging Face},
6 howpublished = {(https://huggingface.co/CS221DoAn/Do_an_group_CRF)}
7}
8