--- dataset_info: features: - name: example_id dtype: int64 - name: query dtype: string - name: query_id dtype: int64 - name: product_id dtype: string - name: product_locale dtype: string - name: esci_label dtype: string - name: small_version dtype: int64 - name: large_version dtype: int64 - name: split dtype: string - name: product_title dtype: string - name: product_description dtype: string - name: product_bullet_point dtype: string - name: product_brand dtype: string - name: product_color dtype: string - name: source dtype: string - name: full_description dtype: string - name: Boost Product Index dtype: int64 - name: description dtype: string splits: - name: train num_bytes: 130485155 num_examples: 13985 download_size: 58648377 dataset_size: 130485155 configs: - config_name: default data_files: - split: train path: data/train-* --- This dataset is a sample for the [`Amazon Shopping Queries Dataset`](https://github.com/amazon-science/esci-data). This dataset contains queries for which at least 10 products are available. The products if possible are `exact` matches to the query intent, or at least `substitutes` It was constructed as follows: ``` import pandas as pd df_examples = pd.read_parquet("shopping_queries_dataset_examples.parquet") df_products = pd.read_parquet("shopping_queries_dataset_products.parquet") df_sources = pd.read_csv("shopping_queries_dataset_sources.csv") df_examples_products = pd.merge( df_examples, df_products, how="left", left_on=["product_locale", "product_id"], right_on=["product_locale", "product_id"], ) df_examples_products_source = pd.merge( df_examples_products, df_sources, how="left", left_on=["query_id"], right_on=["query_id"], ) list_hits = [] for query_id in tqdm(list_query_id): df = retrieve_products(query_id, df_examples_products_source) list_len_desc = [] for row_idx in range(len(df)): row = df.iloc[row_idx] full_description = format_product_details(row) list_len_desc.append(len(full_description)) if len(df) >= 10: list_hits.append((df, np.mean(list_len_desc))) # sort by length of full_description list_hits = sorted(list_hits, key=lambda x: x[1], reverse=True) df = pd.concat([x[0] for x in list_hits[:1000]]) ``` The auxiliary functions are: ``` def format_product_details(product): template = "List of features:\n{features}\n\nDescription:\n{description}" features = product["product_bullet_point"] description = product["product_description"] return template.format(features=features, description=description) def retrieve_products(query_id, df_examples_products_source): df = df_examples_products_source[ df_examples_products_source["query_id"] == query_id ] # product_locale = en df = df[df["product_locale"] == "us"] # remove esci_label I df = df[df["esci_label"] != "I"] # remove product_description None df = df[df["product_description"].notnull()] # remove product_bullet_point None df = df[df["product_bullet_point"].notnull()] # if esci_label E > 10, use only those if df[df["esci_label"] == "E"].shape[0] > 10: df = df[df["esci_label"] == "E"] # if esci_label in [E, S ]> 10, use only those elif df[df["esci_label"].isin(["E", "S"])].shape[0] > 10: df = df[df["esci_label"].isin(["E", "S else: return [] return df ```