File size: 3,560 Bytes
f0f2280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Example usage of the B2B Ecommerce NER model for Hugging Face
"""

import sys
import os
sys.path.append(os.path.dirname(__file__))

from model import B2BEcommerceNER


def main():
    """Demonstrate the B2B Ecommerce NER model usage"""
    
    print("B2B Ecommerce NER Model - Example Usage")
    print("=" * 50)
    
    # Sample B2B order texts
    sample_orders = [
        "Order 5 bottles of Coca Cola 650ML",
        "I need 10 packs of Maggi noodles 200G each",
        "Send 3 units of Chocolate Cleanser 500ML",
        "Please deliver 15 pieces of Golden Dates 250G",
        "We want 8 cases of mineral water 1L bottles"
    ]
    
    try:
        # Initialize the model (without loading since we don't have the actual model files yet)
        print("Initializing B2B Ecommerce NER model...")
        model = B2BEcommerceNER()
        
        print("Model configuration:")
        print(f"- Entity labels: {model.entity_labels}")
        print(f"- Model path: {model.model_path}")
        print(f"- Catalog path: {model.catalog_path}")
        
        print("\nSample order processing would work like this:")
        print("-" * 40)
        
        for i, order in enumerate(sample_orders, 1):
            print(f"\n{i}. Order: '{order}'")
            print("   Expected entities:")
            
            # Manually show expected results (since model isn't loaded)
            if "5 bottles of Coca Cola 650ML" in order:
                print("   - QUANTITY: '5'")
                print("   - UNIT: 'bottles'") 
                print("   - PRODUCT: 'Coca Cola'")
                print("   - SIZE: '650ML'")
            elif "10 packs of Maggi" in order:
                print("   - QUANTITY: '10'")
                print("   - UNIT: 'packs'")
                print("   - PRODUCT: 'Maggi noodles'")
                print("   - SIZE: '200G'")
            elif "3 units of Chocolate Cleanser" in order:
                print("   - QUANTITY: '3'")
                print("   - UNIT: 'units'")
                print("   - PRODUCT: 'Chocolate Cleanser'")
                print("   - SIZE: '500ML'")
            elif "15 pieces of Golden Dates" in order:
                print("   - QUANTITY: '15'")
                print("   - UNIT: 'pieces'")
                print("   - PRODUCT: 'Golden Dates'")
                print("   - SIZE: '250G'")
            elif "8 cases of mineral water" in order:
                print("   - QUANTITY: '8'")
                print("   - UNIT: 'cases'")
                print("   - PRODUCT: 'mineral water'")
                print("   - SIZE: '1L'")
        
        print("\n" + "=" * 50)
        print("To use with actual trained model:")
        print("1. Train your model using the main training pipeline")
        print("2. Copy the trained spaCy model to huggingface_model/spacy_model/")
        print("3. Copy product_catalog.csv to huggingface_model/")
        print("4. Use model.predict(texts) for actual entity extraction")
        
        print("\nCode example:")
        print("""
# Load pre-trained model
model = B2BEcommerceNER.from_pretrained('path/to/saved/model')

# Extract entities
results = model.predict(['Order 5 Coke Zero 650ML'])

# Access entities
entities = results[0]['entities']
products = entities['products']
quantities = entities['quantities']
catalog_matches = entities['catalog_matches']
""")
        
    except Exception as e:
        print(f"Note: {e}")
        print("This is expected since the actual model files are not loaded yet.")


if __name__ == "__main__":
    main()