|
--- |
|
library_name: transformers |
|
tags: [] |
|
--- |
|
|
|
# Model Card for Model ID |
|
|
|
This model is designed to identify whether two product titles (including specifications) describe the same product. The model generates a score, where a score greater than 0.5 indicates that the products are likely the same. The threshold value can be used as needed. It is based on the BERT base uncased architecture and has been fine-tuned on a custom dataset derived from real-world examples. The model performs particularly well on longer sequences. |
|
|
|
|
|
|
|
## Model Details |
|
|
|
### Model Description |
|
|
|
<!-- Provide a longer summary of what this model is. --> |
|
|
|
|
|
- **Model type:** Binary Classification |
|
- **Language(s) (NLP):** English |
|
- **Finetuned from model:** bert-base-uncased |
|
|
|
|
|
|
|
## Uses |
|
|
|
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. --> |
|
|
|
### Direct Use |
|
|
|
This model can be directly used to determine if two product titles are the same. It is especially useful in e-commerce applications for deduplication, catalog matching, and product comparison. |
|
|
|
|
|
|
|
### Out-of-Scope Use |
|
|
|
The model is not suitable for tasks requiring deep contextual understanding beyond product titles or for comparing product descriptions that lack specification details. |
|
|
|
|
|
|
|
## Bias, Risks, and Limitations |
|
|
|
- **Bias**: The model may inherit biases present in the dataset, particularly related to product categories with less representation. |
|
- **Limitations**: The model is optimized for product titles and may perform poorly on short, ambiguous titles or non-standardized names. |
|
|
|
### Recommendations |
|
|
|
It is recommended to use this model for products with clearly defined titles and specifications. Users should also monitor performance on specific product categories to identify and address any biases. |
|
|
|
|
|
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations. |
|
|
|
## How to Get Started with the Model |
|
|
|
```python |
|
import torch |
|
from transformers import BertTokenizer |
|
from huggingface_hub import hf_hub_download |
|
|
|
# Step 1: Download model.py |
|
file_path = hf_hub_download(repo_id='Berketarak/Product-Matching-Classifier', filename='model.py') |
|
|
|
# Step 2: Add directory containing model.py to the Python path |
|
import sys, os |
|
model_dir = os.path.dirname(file_path) |
|
sys.path.append(model_dir) |
|
|
|
# Step 3: Import custom model class |
|
from model import CustomBertModel |
|
|
|
# Step 4: Load tokenizer and model |
|
tokenizer = BertTokenizer.from_pretrained('Berketarak/Product-Matching-Classifier') |
|
model = CustomBertModel.from_pretrained('Berketarak/Product-Matching-Classifier') |
|
|
|
# Send model to GPU |
|
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') |
|
model.to(device) |
|
|
|
# Define the products |
|
product1 = 'X brand Pegasus Sneakers' |
|
product2 = 'Y brand Shoes' |
|
|
|
# Tokenize the input |
|
inputs = tokenizer(product1, product2, padding='max_length', truncation=True, max_length=350, return_tensors='pt') |
|
|
|
# Inference |
|
with torch.no_grad(): |
|
input_ids = inputs['input_ids'].to(device) |
|
attention_mask = inputs['attention_mask'].to(device) |
|
token_type_ids = inputs['token_type_ids'].to(device) |
|
output = model(input_ids, attention_mask, token_type_ids).item() |
|
|
|
# Interpret the output |
|
if output > 0.5: |
|
print(f"The products are likely the SAME. Model output: {output}") |
|
else: |
|
print(f"The products are likely DIFFERENT. Model output: {output}") |
|
|