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+
- finance
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
# Product Price Predictor Weights
|
| 13 |
+
|
| 14 |
+
A Bi-LSTM model trained to predict e-commerce product prices from textual descriptions.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## Model Details
|
| 19 |
+
|
| 20 |
+
- **Model type:** Bi-directional LSTM (Keras)
|
| 21 |
+
- **Task:** Regression (price prediction)
|
| 22 |
+
- **Input:** Product description (text)
|
| 23 |
+
- **Output:** Predicted price (USD)
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## Intended Use
|
| 28 |
+
|
| 29 |
+
This model is designed to provide quick, approximate pricing for small-to-medium sized e-commerce catalogs where descriptions follow a consistent style (e.g., electronics or appliances). It **should not** be used:
|
| 30 |
+
|
| 31 |
+
- For precise financial appraisal or high-stakes bidding.
|
| 32 |
+
- On descriptions with highly technical jargon the model wasn’t trained on.
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## Limitations
|
| 37 |
+
|
| 38 |
+
- **Domain sensitivity:** Trained on the `Recompense/amazon-appliances-lite-data` dataset—performance may degrade on other product categories.
|
| 39 |
+
- **Short descriptions:** Very long or unstructured text may reduce accuracy.
|
| 40 |
+
- **Price range:** Only learns the range present in the training data (~\$10–\$500).
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Training
|
| 45 |
+
|
| 46 |
+
- **Dataset:** `Recompense/amazon-appliances-lite-data`
|
| 47 |
+
- **Preprocessing:**
|
| 48 |
+
- Text vectorization (max 10 000 tokens)
|
| 49 |
+
- Embedding dimension: 128
|
| 50 |
+
- **Architecture:**
|
| 51 |
+
1. Embedding → Bi-LSTM(64) → Bi-LSTM(64) → Dense(1)
|
| 52 |
+
- **Optimizer:** Adam, learning rate 1e-3
|
| 53 |
+
- **Epochs:** 20, batch size 32
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## Evaluation
|
| 58 |
+
|
| 59 |
+
- **Metric:** Root Mean Squared Logarithmic Error (RMSLE)
|
| 60 |
+
- **Formula (display mode):**
|
| 61 |
+
|
| 62 |
+
$$
|
| 63 |
+
RMSLE = \sqrt{ \frac{1}{n} \sum_{i=1}^{n} \bigl(\log(1 + \hat{y}_i) - \log(1 + y_i)\bigr)^2 }
|
| 64 |
+
$$
|
| 65 |
+
|
| 66 |
+
- **Test RMSLE:** 0.145 on held-out validation set
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## Files
|
| 71 |
+
|
| 72 |
+
- **`model_weights.h5`** – Trained Keras weights
|
| 73 |
+
- **`model_config.json`** – Model architecture config
|
| 74 |
+
- **`vectorizer_config.json`** – Text vectorization config
|
| 75 |
+
|
| 76 |
+
---
|
| 77 |
+
|
| 78 |
+
## Usage
|
| 79 |
+
|
| 80 |
+
Below is an end-to-end example showing how to load the model from the Hugging Face Hub, set your preferred Keras backend, and run inference using the helper function:
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
# 1) Install dependencies (if needed)
|
| 84 |
+
# pip install tensorflow jax keras huggingface_hub
|
| 85 |
+
|
| 86 |
+
# 2) Choose your backend: "jax", "torch", or "tensorflow"
|
| 87 |
+
import os
|
| 88 |
+
os.environ["KERAS_BACKEND"] = "jax" # or "torch", or "tensorflow"
|
| 89 |
+
|
| 90 |
+
# 3) Load Keras and the model from the Hub
|
| 91 |
+
from keras.saving import load_model
|
| 92 |
+
|
| 93 |
+
model = load_model("hf://Recompense/product-pricer-bilstm")
|
| 94 |
+
|
| 95 |
+
# 4) Define your inference function
|
| 96 |
+
import tensorflow as tf
|
| 97 |
+
|
| 98 |
+
def bilstm_pricer(item_text: str) -> int:
|
| 99 |
+
"""
|
| 100 |
+
Predict the price of a product given its description.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
item_text (str): The full prompt text, including any prefix.
|
| 104 |
+
Only the description (after the first blank line) is used.
|
| 105 |
+
|
| 106 |
+
Returns:
|
| 107 |
+
int: The rounded, non-negative predicted price in USD.
|
| 108 |
+
"""
|
| 109 |
+
# Extract just the product description (assuming a prefix question)
|
| 110 |
+
try:
|
| 111 |
+
description = item_text.split('\n\n', 1)[1]
|
| 112 |
+
except IndexError:
|
| 113 |
+
description = item_text
|
| 114 |
+
|
| 115 |
+
# Vectorize and batch the text
|
| 116 |
+
text_tensor = tf.convert_to_tensor([description])
|
| 117 |
+
|
| 118 |
+
# Model prediction
|
| 119 |
+
pred = model.predict(text_tensor, verbose=0)[0][0]
|
| 120 |
+
|
| 121 |
+
# Post-process: clamp and round
|
| 122 |
+
pred = max(0.0, pred)
|
| 123 |
+
return round(pred)
|
| 124 |
+
|
| 125 |
+
# 5) Example inference
|
| 126 |
+
prompt = (
|
| 127 |
+
"What is a fair price for the following appliance?\n\n"
|
| 128 |
+
"Stainless steel 12-cup programmable coffee maker with auto-shutoff"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
predicted_price = bilstm_pricer(prompt)
|
| 132 |
+
print(f"Predicted price: ${predicted_price}")
|
| 133 |
+
```
|