A Bi-LSTM model trained to predict e-commerce product prices from textual descriptions.
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:
$$
RMSLE = \sqrt{ \frac{1}{n} \sum_{i=1}^{n} \bigl(\log(1 + \hat{y}_i) - \log(1 + y_i)\bigr)^2 }
$$
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:
1# 1) Install dependencies (if needed)
2# pip install tensorflow jax keras huggingface_hub
3
4# 2) Choose your backend: "jax", "torch", or "tensorflow"
5import os
6os.environ["KERAS_BACKEND"] = "jax" # or "torch", or "tensorflow"
7
8# 3) Load Keras and the model from the Hub
9from keras.saving import load_model
10
11model = load_model("hf://Recompense/product-pricer-bilstm")
12
13# 4) Define your inference function
14import tensorflow as tf
15
16def bilstm_pricer(item_text: str) -> int:
17 """
18 Predict the price of a product given its description.
19
20 Args:
21 item_text (str): The full prompt text, including any prefix.
22 Only the description (after the first blank line) is used.
23
24 Returns:
25 int: The rounded, non-negative predicted price in USD.
26 """
27 # Extract just the product description (assuming a prefix question)
28 try:
29 description = item_text.split('\n\n', 1)[1]
30 except IndexError:
31 description = item_text
32
33 # Vectorize and batch the text
34 text_tensor = tf.convert_to_tensor([description])
35
36 # Model prediction
37 pred = model.predict(text_tensor, verbose=0)[0][0]
38
39 # Post-process: clamp and round
40 pred = max(0.0, pred)
41 return round(pred)
42
43# 5) Example inference
44prompt = (
45 "What is a fair price for the following appliance?\n\n"
46 "Stainless steel 12-cup programmable coffee maker with auto-shutoff"
47)
48
49predicted_price = bilstm_pricer(prompt)
50print(f"Predicted price: ${predicted_price}")