Dataset Viewer
Auto-converted to Parquet
parent_asin
stringlengths
10
10
semantic_id
stringlengths
66
68
title
stringlengths
21
620
B000FH0MHO
<|sid_start|><|sid_32|><|sid_486|><|sid_636|><|sid_768|><|sid_end|>
Dash 8-300 Professional Add-On
B00Z9TLVK0
<|sid_start|><|sid_188|><|sid_400|><|sid_518|><|sid_769|><|sid_end|>
NBA 2K17 - Early Tip Off Edition - PlayStation 4
B002WH4ZJG
<|sid_start|><|sid_198|><|sid_262|><|sid_684|><|sid_768|><|sid_end|>
Thrustmaster Elite Fitness Pack for Nintendo Wii
B0001ZNU56
<|sid_start|><|sid_65|><|sid_483|><|sid_757|><|sid_768|><|sid_end|>
Spongebob Squarepants, Vol. 1
B009C9E8JY
<|sid_start|><|sid_154|><|sid_414|><|sid_585|><|sid_768|><|sid_end|>
Set of 4 Bullet Buttons Nickel+Brass for Playstation PS3 PS2 controllers
B00006969T
<|sid_start|><|sid_169|><|sid_506|><|sid_746|><|sid_768|><|sid_end|>
Konami Collector's Series: Castlevania & Contra - PC
B07DL353F8
<|sid_start|><|sid_74|><|sid_398|><|sid_583|><|sid_768|><|sid_end|>
Tales of Vesperia - Definitive Edition - PlayStation 4
B00BJH85SW
<|sid_start|><|sid_201|><|sid_345|><|sid_679|><|sid_768|><|sid_end|>
Turbo: Super Stunt Squad - Nintendo 3DS
B07J1TD61J
<|sid_start|><|sid_105|><|sid_434|><|sid_584|><|sid_768|><|sid_end|>
SteelSeries Arctis Pro + GameDAC Wired Gaming Headset - Certified Hi-Res Audio - Dedicated DAC and Amp - for PS5/PS4 and PC - White
B001EYUX4Y
<|sid_start|><|sid_92|><|sid_299|><|sid_615|><|sid_768|><|sid_end|>
Warhammer 40,000 Dawn of War Game of the Year - PC
B014BNPNVM
<|sid_start|><|sid_161|><|sid_307|><|sid_653|><|sid_768|><|sid_end|>
Blue Flame Skull Vinyl Skin Decal Sticker for 3DS XL
B001ECIV54
<|sid_start|><|sid_142|><|sid_503|><|sid_670|><|sid_768|><|sid_end|>
Scooby Doo Who's Watching - Sony PSP
B00004SVXD
<|sid_start|><|sid_25|><|sid_476|><|sid_515|><|sid_768|><|sid_end|>
Tiger Heli - Nintendo NES
B0725ZD6QD
<|sid_start|><|sid_188|><|sid_354|><|sid_661|><|sid_768|><|sid_end|>
Pro Evolution Soccer 2018 - Xbox One Legendary Edition
B00K3T7D4E
<|sid_start|><|sid_47|><|sid_488|><|sid_603|><|sid_769|><|sid_end|>
MLB Minnesota Twins Distressed Skin for Sony PlayStation 4/PS4 Dual Shock4 Controller, Blue
B07B3RPWKK
<|sid_start|><|sid_213|><|sid_280|><|sid_690|><|sid_768|><|sid_end|>
CORSAIR K95 RGB PLATINUM Mechanical Gaming Keyboard - USB Passthrough & Media Controls - Tactile & Quiet - Cherry MX Brown - RGB LED Backlit (Renewed)
B08TBXXCZW
<|sid_start|><|sid_60|><|sid_326|><|sid_707|><|sid_768|><|sid_end|>
Decal Moments PS5 Standard Disc Console Controllers Full Body Vinyl Skin Sticker Decals for Playstation 5 Console and Controllers Avengers
B08928XH3Y
<|sid_start|><|sid_133|><|sid_482|><|sid_528|><|sid_768|><|sid_end|>
TXEsign Wall Mount Holder for Nintendo Switch Dock Station Adhesive Small Wall Shelf Floating Wall Mount Stand for Switch Dock(Silky White & Transparent)
B004BLJPZU
<|sid_start|><|sid_183|><|sid_345|><|sid_517|><|sid_768|><|sid_end|>
MX vs ATV Reflex [Download]
B005ILK04M
<|sid_start|><|sid_19|><|sid_275|><|sid_759|><|sid_768|><|sid_end|>
CH PRODUCTS Eclipse Yoke Discover Bundle (200616DIS)
B0013953N6
<|sid_start|><|sid_191|><|sid_314|><|sid_644|><|sid_768|><|sid_end|>
Universal Remote Control For X Box 360 & PS II, Playstation 2, Systems Does not need programing.
B00BW800LI
<|sid_start|><|sid_162|><|sid_294|><|sid_570|><|sid_768|><|sid_end|>
Cobi Treasure Deluxe [Download]
B08XXJLZ8N
<|sid_start|><|sid_239|><|sid_352|><|sid_572|><|sid_768|><|sid_end|>
Deep Tissue Percussion Muscle Cellulite Massager,Handheld Electric Full Body Therapy Massage Gun for Sore Muscle, Stiffness, Sciatica and Back Pain,Including 4 Massage Heads,Gift for him or her
B0011UH182
<|sid_start|><|sid_69|><|sid_499|><|sid_718|><|sid_768|><|sid_end|>
Tom Clancy's Ghost Recon Advanced Warfighter
B0000690NH
<|sid_start|><|sid_212|><|sid_431|><|sid_716|><|sid_768|><|sid_end|>
Wizmo's Workshop: Dragons of Frozzbokk - PC
B072KHS2P7
<|sid_start|><|sid_83|><|sid_491|><|sid_716|><|sid_768|><|sid_end|>
Nyko Travel Charger EX - 6ft. USB Type - C to Car Charger (12V Power Port) for Nintendo Switch - Power Delivery Compatible with New MacBook Pro
B00OLOQGAY
<|sid_start|><|sid_105|><|sid_268|><|sid_749|><|sid_768|><|sid_end|>
Polk Audio Striker Zx Xbox One Gaming Headset - Black
B07TQYRVSZ
<|sid_start|><|sid_131|><|sid_354|><|sid_516|><|sid_768|><|sid_end|>
Wreckfest - Deluxe Edition - PlayStation 4
B07D482RJ8
<|sid_start|><|sid_54|><|sid_354|><|sid_562|><|sid_768|><|sid_end|>
10FT Long PS4 Charger Cord for Xbox One Controller,PS4 Charging Cable,Micro USB Cable for Xbox One S/X Slim Elite Controller,Playstation 4 Games,Dualshock 4 Controller Data Sync Cord Wire
B09XSJ282Q
<|sid_start|><|sid_42|><|sid_465|><|sid_705|><|sid_768|><|sid_end|>
Crescent Marketing and Distribution Deathsmiles I&II for PlayStation 4
B08CRMC56N
<|sid_start|><|sid_216|><|sid_287|><|sid_702|><|sid_768|><|sid_end|>
Fpxnb 4 Pairs Switch Thumb Grip Set, Analog Stick Silicone Cap Joystick Covers, Cat Claw & Sakura Flower Design, Compatible with Switch Joy-Con Controllers & Lite, Pink & Blue
B002KAKSJQ
<|sid_start|><|sid_14|><|sid_335|><|sid_650|><|sid_769|><|sid_end|>
Art of Murder: Cards of Destiny - PC
B01CEY4CTY
<|sid_start|><|sid_33|><|sid_261|><|sid_586|><|sid_771|><|sid_end|>
NINTENDO World of Nintendo Squid Plush, Blue
B01702K36Q
<|sid_start|><|sid_157|><|sid_320|><|sid_616|><|sid_768|><|sid_end|>
Lost in Reefs: Antarctic [Download]
B00R6HCZ0I
<|sid_start|><|sid_113|><|sid_407|><|sid_725|><|sid_768|><|sid_end|>
Valiant Hearts - Xbox One Digital Code
B00H5NRSAK
<|sid_start|><|sid_101|><|sid_379|><|sid_557|><|sid_768|><|sid_end|>
Assecure camouflage camo protect & grip pack soft silicone skin grip prot.
B09V6PJ1SC
<|sid_start|><|sid_225|><|sid_333|><|sid_532|><|sid_768|><|sid_end|>
Motu Origins Protective Cases by Nozlen - Masters of The Universe - HE-Man - WWE
B08BC1PZ1T
<|sid_start|><|sid_85|><|sid_364|><|sid_638|><|sid_768|><|sid_end|>
KOET Game Handbrake, Racing Games USB Handbrake for SIM Racing Games G25 G29 T500, Universal Horizontal Drift Rally Racing Handbrake for PC/Windows
B004BV5O0U
<|sid_start|><|sid_197|><|sid_461|><|sid_556|><|sid_768|><|sid_end|>
The Legend of Heroes: Trails in the Sky - Sony PSP
B001ELJEA6
<|sid_start|><|sid_197|><|sid_487|><|sid_628|><|sid_768|><|sid_end|>
Harry Potter: Goblet of Fire - Sony PSP
B00B5QGJ5S
<|sid_start|><|sid_139|><|sid_283|><|sid_570|><|sid_768|><|sid_end|>
The Last Of Us Remastered - PS4 [Digital Code]
B08CN5LC3Y
<|sid_start|><|sid_240|><|sid_323|><|sid_707|><|sid_769|><|sid_end|>
Switch Lite Case,Protective Cover Case for Switch Lite with Anti-Scratch Design
B00GW6VBOK
<|sid_start|><|sid_166|><|sid_292|><|sid_621|><|sid_768|><|sid_end|>
Arsenal Gaming AP3KIT1 2-In-1 Mini Wired Controller Kit, Clear and Smoke - PlayStation 3
B09CG15F86
<|sid_start|><|sid_104|><|sid_430|><|sid_602|><|sid_768|><|sid_end|>
Razer Doubleshot PBT Keycap Upgrade Set for Mechanical & Optical Keyboards: Compatible with Standard 104/105 US and UK layouts - Classic Black
B00002ST5F
<|sid_start|><|sid_65|><|sid_484|><|sid_574|><|sid_768|><|sid_end|>
Speedy Gonzales Aztec Adventure
B00JYA880G
<|sid_start|><|sid_241|><|sid_505|><|sid_747|><|sid_769|><|sid_end|>
Book Club - Hidden Object Game [Download]
B06Y3SRCTN
<|sid_start|><|sid_92|><|sid_361|><|sid_521|><|sid_768|><|sid_end|>
Tropico 5 - Complete Collection - Xbox One
B07JKM5FVP
<|sid_start|><|sid_238|><|sid_323|><|sid_600|><|sid_768|><|sid_end|>
The Sims 4 Get Famous - PC
B00002SUAF
<|sid_start|><|sid_160|><|sid_428|><|sid_639|><|sid_768|><|sid_end|>
Power Rangers Zeo Pinball - PlayStation
B002KE4NVG
<|sid_start|><|sid_230|><|sid_344|><|sid_579|><|sid_768|><|sid_end|>
Tales of Monkey Island: Chapter 1 [Download]
B0816HC1H7
<|sid_start|><|sid_80|><|sid_321|><|sid_761|><|sid_768|><|sid_end|>
eXtremeRate Black Vertical Stand for Xbox One S Console
B00GYL29NU
<|sid_start|><|sid_220|><|sid_471|><|sid_644|><|sid_768|><|sid_end|>
Injustice: Gods Among Us - Ultimate Edition /ps4
B0013WI4L6
<|sid_start|><|sid_140|><|sid_390|><|sid_720|><|sid_768|><|sid_end|>
XFPS RATEUP adapter for PLAYSTATION 3
B07GQVD13S
<|sid_start|><|sid_158|><|sid_333|><|sid_657|><|sid_768|><|sid_end|>
THRUSTMASTER T80 Ferrari 488 GTB Edition (PS4 / PC)
B001EYUWL8
<|sid_start|><|sid_92|><|sid_416|><|sid_568|><|sid_768|><|sid_end|>
Tom Clancy's EndWar - Nintendo DS
B006M38RX6
<|sid_start|><|sid_157|><|sid_500|><|sid_618|><|sid_768|><|sid_end|>
Committed: Mystery at Shady Pines [Download]
B00AA55K50
<|sid_start|><|sid_110|><|sid_425|><|sid_600|><|sid_768|><|sid_end|>
Bubble Burst Remix JC
B01LP5V5CU
<|sid_start|><|sid_24|><|sid_321|><|sid_663|><|sid_768|><|sid_end|>
Controller Gear Officially Licensed Gears of War 4 Crimson Omen - Limited Edition Controller Stand v2.0 - Red. “Controller not included”
B08865S99Z
<|sid_start|><|sid_240|><|sid_265|><|sid_683|><|sid_768|><|sid_end|>
LEGELUX Comfortable Silicone Case for Nintendo Switch Lite, Creative Design with Full Protection Body Protective Cover for Nintendo Switch Lite - Yellow
B00BN5T30E
<|sid_start|><|sid_69|><|sid_406|><|sid_590|><|sid_769|><|sid_end|>
Assassin's Creed IV Black Flag - PC
B000EP3ZLC
<|sid_start|><|sid_125|><|sid_473|><|sid_549|><|sid_768|><|sid_end|>
Dreamfall: The Longest Journey - PC
B002XUKTT2
<|sid_start|><|sid_212|><|sid_347|><|sid_631|><|sid_768|><|sid_end|>
Delicious: Emily's Holiday Season [Download]
B000WQ3838
<|sid_start|><|sid_131|><|sid_499|><|sid_616|><|sid_768|><|sid_end|>
Midnight Club: Los Angeles - Playstation 3
B073S47LKD
<|sid_start|><|sid_165|><|sid_503|><|sid_712|><|sid_768|><|sid_end|>
Ghost Files: The Face of Guilt Collector's Edition [Download]
B0025KW024
<|sid_start|><|sid_94|><|sid_269|><|sid_574|><|sid_768|><|sid_end|>
Success Story [Download]
B001TMU0CG
<|sid_start|><|sid_58|><|sid_290|><|sid_544|><|sid_768|><|sid_end|>
Agatha Christie: Triple Murder Mystery Pack (And Then There Were None + Murder on the Orient Express + Evil Under the Sun)
B07GN75XN1
<|sid_start|><|sid_224|><|sid_290|><|sid_646|><|sid_768|><|sid_end|>
Mario + Rabbids Kingdom Battle Donkey Kong Adventure DLC - Nintendo Switch [Digital Code]
B093H7R8XV
<|sid_start|><|sid_136|><|sid_502|><|sid_519|><|sid_768|><|sid_end|>
Cooling Fan for Xbox Series X, External USB Cooler Cooling System with USB Hub Port for Xbox Series X Console
B0BLP6FW67
<|sid_start|><|sid_202|><|sid_386|><|sid_712|><|sid_768|><|sid_end|>
Nintendo Switch OLED Model: Pokemon Scarlet & Violet Edition (Renewed)
B00004XOKM
<|sid_start|><|sid_1|><|sid_353|><|sid_515|><|sid_768|><|sid_end|>
Star Wars: Pit Droids - PC/Mac
B005OBY876
<|sid_start|><|sid_244|><|sid_360|><|sid_708|><|sid_768|><|sid_end|>
POSTAL 2: Apocalypse Weekend [Download]
B00GUNLZ00
<|sid_start|><|sid_128|><|sid_276|><|sid_617|><|sid_768|><|sid_end|>
YOU DON'T KNOW JACK Volume 1 XL [Download]
B00004U2H6
<|sid_start|><|sid_120|><|sid_425|><|sid_767|><|sid_768|><|sid_end|>
Diablo 2: Extra Large T-Shirt
B009156SHE
<|sid_start|><|sid_183|><|sid_508|><|sid_713|><|sid_768|><|sid_end|>
Forza Motorsport 4 Limited Collector's Edition (English/Spanish Version)
B001RNOQLS
<|sid_start|><|sid_166|><|sid_473|><|sid_530|><|sid_768|><|sid_end|>
PS3 Shadow Wireless Controller with Rumble
B07SG171WL
<|sid_start|><|sid_51|><|sid_508|><|sid_689|><|sid_768|><|sid_end|>
DOOM Eternal: Collector's Edition - Xbox One
B006IVOLCI
<|sid_start|><|sid_118|><|sid_307|><|sid_716|><|sid_768|><|sid_end|>
Playstation Move Mayhem Bundle for Playstation 3
B015Q7IF3U
<|sid_start|><|sid_246|><|sid_356|><|sid_606|><|sid_768|><|sid_end|>
NewNewStar® Replacement Power Supply Cord Wall AC Adapter Supply Cord Cable for Nintendo Wii
B00ZLI9MR8
<|sid_start|><|sid_191|><|sid_333|><|sid_760|><|sid_768|><|sid_end|>
Gioteck Online Gaming Pack for PS4
B07KXS41QL
<|sid_start|><|sid_148|><|sid_409|><|sid_758|><|sid_768|><|sid_end|>
Nyko Charge Block Duo - 2 Port Controller Charging Station with Patented Charging Dongles and Micro-USB/AC Power Cord for PlayStation 4
B01J4JTNTG
<|sid_start|><|sid_20|><|sid_487|><|sid_596|><|sid_772|><|sid_end|>
Gamer Gloves Limited Edition - Orange - Small
B00XY0IVK4
<|sid_start|><|sid_188|><|sid_333|><|sid_631|><|sid_768|><|sid_end|>
NHL 16 - PlayStation 4
B00005V9O0
<|sid_start|><|sid_145|><|sid_319|><|sid_667|><|sid_768|><|sid_end|>
Nascar Heat 2002, Racing, Game Boy Advance
B07VTR7B18
<|sid_start|><|sid_30|><|sid_436|><|sid_757|><|sid_768|><|sid_end|>
Redragon K503 PC Gaming Keyboard, Wired, Multimedia Keys, Silent USB Keyboard with Wrist Rest for Windows PC Games (RGB LED Backlit with Macro Recording)
B07W9955Z4
<|sid_start|><|sid_231|><|sid_261|><|sid_588|><|sid_768|><|sid_end|>
Hyperkin EVA Hard Shell Carrying Case for Nintendo Switch Lite (White/Turquoise)
B00008DHLK
<|sid_start|><|sid_168|><|sid_267|><|sid_663|><|sid_768|><|sid_end|>
X2 Wolverine's Revenge
B094JWT2M7
<|sid_start|><|sid_30|><|sid_376|><|sid_625|><|sid_768|><|sid_end|>
Rainbow Gaming Keyboard and Mouse Combo,LED Backlit Light up Full-Sized 104 Keys Gaming Keyboard with Colorful Gaming Mouse for PS4 Mac Laptop Gamer
B0B6BF97TZ
<|sid_start|><|sid_210|><|sid_429|><|sid_533|><|sid_769|><|sid_end|>
NBA 2K23 Michael Jordan Edition - Xbox Series X
B0001AVSH8
<|sid_start|><|sid_205|><|sid_448|><|sid_563|><|sid_768|><|sid_end|>
Hitman Contracts - Xbox
B00R6OLQGA
<|sid_start|><|sid_60|><|sid_413|><|sid_671|><|sid_769|><|sid_end|>
ModFreakz® Console/Controller Vinyl Skin Set - Green Hair Evil Grin for PS4 Original
B0000CE1IN
<|sid_start|><|sid_125|><|sid_428|><|sid_673|><|sid_768|><|sid_end|>
Black and White Deluxe - PC
B077JPRCMH
<|sid_start|><|sid_93|><|sid_384|><|sid_682|><|sid_770|><|sid_end|>
Whiteoak PS4 Keyboard, Wireless Mini Backlit Chatpad, Great KeyPad Adapter for PlayStation 4 PS4, Slim, Pro Controller - 2.4GHz Receiver included
B07FQPQ7RH
<|sid_start|><|sid_68|><|sid_500|><|sid_666|><|sid_768|><|sid_end|>
CXCase 2017 SADES CX-778 PS4 Xbox One 3.5mm Gaming Headset Over-Ear Gaming Headphones with Mic, Volume Control, Noise Cancelling, Headphone Case for PC, Smart Phones, Tablet, Laptops (Black Red)
B00OVGABF8
<|sid_start|><|sid_77|><|sid_420|><|sid_736|><|sid_768|><|sid_end|>
Dark Parables JACK AND THE SKY KINGDOM Hidden Object PC Game + BONUS
B00LHKVUBK
<|sid_start|><|sid_196|><|sid_301|><|sid_748|><|sid_768|><|sid_end|>
SODIAL(R) Rechargeable Replacement Battery Compatible with Sony PSP 2000
B07QN1KG7D
<|sid_start|><|sid_160|><|sid_333|><|sid_514|><|sid_768|><|sid_end|>
Tennis World Tour Roland-Garros Edition (PS4) - PlayStation 4
B078GLDBZX
<|sid_start|><|sid_250|><|sid_342|><|sid_694|><|sid_768|><|sid_end|>
Street Fighter 30th Anniversary Collection - Nintendo Switch Standard Edition
B0000C0YSB
<|sid_start|><|sid_238|><|sid_425|><|sid_568|><|sid_768|><|sid_end|>
The Sims: Double Deluxe - PC
B099WMXYGH
<|sid_start|><|sid_245|><|sid_325|><|sid_710|><|sid_768|><|sid_end|>
CNBEYOUNG Head Back Padding Compatible with Quest 2 Official Soft Head Strap, Gravity Pressure Balance Cushion Accessories for Quest 2,Reduce Pressure Enhance Support in VR Gaming (Black)
B01GY35HKE
<|sid_start|><|sid_251|><|sid_476|><|sid_691|><|sid_768|><|sid_end|>
Mass Effect Andromeda Deluxe - Xbox One
End of preview. Expand in Data Studio

Video Games Semantic IDs with Product Titles

This dataset contains semantic ID mappings with product titles for video games products from Amazon.

See writeup and demo here: https://eugeneyan.com/writing/semantic-ids/

Dataset Description

A pre-joined dataset that maps semantic IDs to product titles, making it easy to interpret and work with hierarchical product embeddings. Semantic IDs are learned representations that encode product relationships - similar products share similar ID prefixes.

Semantic ID Structure

Each semantic ID follows this format: <|sid_start|><|sid_X|><|sid_Y|><|sid_Z|><|sid_W|><|sid_end|>

Where:

  • <|sid_start|> and <|sid_end|> are boundary tokens
  • <|sid_X|>, <|sid_Y|>, <|sid_Z|>, <|sid_W|> represent the 4-level hierarchy
  • Each level can have values from 0-1023
  • Similar products share prefixes (e.g., products with same first 2 levels are more similar)

Dataset Statistics

  • Category: Video Games
  • Number of products: 66,097
  • Hierarchy levels: 4
  • Tokens per level: 1024

Columns

  • parent_asin: Amazon Standard Identification Number (primary key)
  • semantic_id: The hierarchical semantic identifier for the product
  • title: Product title/name for human-readable interpretation

Usage

Basic Loading

from datasets import load_dataset
import pandas as pd

# Load the dataset
dataset = load_dataset("eugeneyan/video-games-semantic-ids-mapping")
mapping_df = dataset['train'].to_pandas()

print(f"Loaded {len(mapping_df)} video games products with semantic IDs and
titles")
print(mapping_df.head())

Parsing Semantic IDs

import re
from typing import List

def parse_semantic_id(semantic_id: str) -> List[str]:
    """
    Parse a semantic ID string into its component levels.

    Example input: '<|sid_start|><|sid_127|><|sid_45|><|sid_89|><|sid_12|><|sid_end|>'
    Returns: ['<|sid_127|>', '<|sid_45|>', '<|sid_89|>', '<|sid_12|>']
    """
    # Remove start and end tokens
    sid = semantic_id.replace("<|sid_start|>", "").replace("<|sid_end|>", "")

    # Extract all sid tokens
    pattern = r"<\|sid_\d+\|>"
    levels = re.findall(pattern, sid)

    return levels

Finding Products with Smart Matching

def map_semantic_id_to_titles(semantic_id_str: str, mapping_df: pd.DataFrame) -> dict:
    """
    Map a semantic ID to titles with 4-token exact match and 3-token fallback.

    Returns:
        dict with 'match_level', 'titles', 'count', and 'match_type' keys
    """
    # Parse the input semantic ID
    levels = parse_semantic_id(semantic_id_str)

    if not levels:
        return {"match_level": 0, "titles": [], "count": 0}

    # First try exact match (all 4 tokens)
    exact_matches = mapping_df[mapping_df["semantic_id"] == semantic_id_str]
    if len(exact_matches) > 0:
        titles = exact_matches["title"].tolist()
        return {"match_level": 4, "titles": titles, "count": len(titles), "match_type":
"exact"}

    # Fallback to prefix matching (3 tokens, then 2, then 1)
    for depth in range(min(3, len(levels)), 0, -1):
        # Build the prefix for this depth
        prefix = "<|sid_start|>" + "".join(levels[:depth])

        # Find matches
        matches = mapping_df[mapping_df["semantic_id"].str.startswith(prefix)]

        if len(matches) > 0:
            # Found matches at this level
            titles = matches["title"].tolist()
            return {
                "match_level": depth,
                "titles": titles[:5],  # Limit to 5 for display
                "count": len(titles),
                "match_type": "prefix",
                "prefix_used": prefix
            }

    # No matches found at any level
    return {"match_level": 0, "titles": [], "count": 0, "match_type": "none"}

# Example usage
sid = "<|sid_start|><|sid_8|><|sid_454|><|sid_630|><|sid_768|><|sid_end|>"
result = map_semantic_id_to_titles(sid, mapping_df)
if result["count"] > 0:
    print(f"Found: {result['titles'][0]} (match level: {result['match_level']})")

Extracting and Replacing Multiple Semantic IDs

def extract_semantic_ids_from_text(text: str) -> List[str]:
    """
    Extract all semantic IDs from a text string.

    Returns list of full semantic IDs found in the text.
    """
    # Pattern to match complete semantic IDs
    pattern = r"<\|sid_start\|>(?:<\|sid_\d+\|>)+<\|sid_end\|>"
    semantic_ids = re.findall(pattern, text)
    return semantic_ids

def replace_semantic_ids_with_titles(text: str, mapping_df: pd.DataFrame,
                                    show_match_level: bool = True) -> str:
    """
    Replace all semantic IDs in text with their corresponding titles.

    Args:
        text: Input text containing semantic IDs
        mapping_df: DataFrame with semantic_id to title mapping
        show_match_level: Whether to append match info after the title

    Returns:
        Text with semantic IDs replaced by titles
    """
    # Find all semantic IDs in the text
    semantic_ids = extract_semantic_ids_from_text(text)

    # Create a copy of the text to modify
    result_text = text

    # Replace each semantic ID with its title(s)
    for sid in semantic_ids:
        # Get matching titles
        match_result = map_semantic_id_to_titles(sid, mapping_df)

        if match_result["count"] > 0:
            # Use the first title if multiple matches
            title = match_result["titles"][0]

            # Add match level if requested
            if show_match_level:
                if match_result["match_type"] == "exact":
                    replacement = f'"{title}"'
                else:
                    replacement = f'"{title}" (L{match_result["match_level"]} match)'
            else:
                replacement = f'"{title}"'

            # If multiple matches, indicate this
            if match_result["count"] > 1:
                replacement += f" [+{match_result['count'] - 1} similar]"
        else:
            # No match found
            replacement = "[Unknown Item]"

        # Replace the semantic ID with the title
        result_text = result_text.replace(sid, replacement)

    return result_text

# Example with model output
model_output = "Recommended: <|sid_start|><|sid_8|><|sid_454|><|sid_630|><|sid_768|><|sid_end|>"
readable_output = replace_semantic_ids_with_titles(model_output, mapping_df)
print(readable_output)  # "Recommended: \"Product Title\""

Finding Similar Products

def find_similar_products(semantic_id: str, mapping_df: pd.DataFrame, depth: int = 2) -> pd.DataFrame:
    """
    Find products with similar semantic IDs by matching prefixes.
    Higher depth = more specific similarity.

    Args:
        semantic_id: The reference semantic ID
        mapping_df: DataFrame with semantic_id and title columns
        depth: Number of hierarchy levels to match (1-4)

    Returns:
        DataFrame with similar products
    """
    # Parse the semantic ID
    levels = parse_semantic_id(semantic_id)

    if not levels or depth < 1:
        return pd.DataFrame()

    # Build prefix for matching
    prefix = "<|sid_start|>" + "".join(levels[:min(depth, len(levels))])

    # Find all products with matching prefix
    similar = mapping_df[mapping_df['semantic_id'].str.startswith(prefix)].copy()

    # Add similarity score (higher = more similar)
    similar['similarity_depth'] = depth

    return similar[['parent_asin', 'semantic_id', 'title', 'similarity_depth']]

# Example: Find products similar at different depths
sid = "<|sid_start|><|sid_8|><|sid_454|><|sid_630|><|sid_768|><|sid_end|>"
similar_at_2 = find_similar_products(sid, mapping_df, depth=2)
print(f"Products in same sub-category (depth 2): {len(similar_at_2)}")

Integration with Model

This dataset is designed to work with the semantic ID recommendation model:

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load model
model_name = "eugeneyan/semantic-id-qwen3-8b-video-games"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

# Generate recommendation
prompt = "User: <|sid_start|><|sid_8|><|sid_454|><|sid_630|><|sid_768|><|sid_end|>\n<|rec|>"
inputs = tokenizer(prompt, return_tensors="pt")

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=50, temperature=0.3, do_sample=True)

# Decode and convert to readable format
response = tokenizer.decode(outputs[0], skip_special_tokens=False)
readable = replace_semantic_ids_with_titles(response, mapping_df)
print(readable)

Understanding Semantic Similarity

The hierarchical structure encodes similarity at different levels:

  • Level 1 match: Broad category similarity
  • Level 2 match: Sub-category similarity
  • Level 3 match: Fine-grained similarity
  • Level 4 match: Very similar or variant products

Example:

  • Product A: <|sid_start|><|sid_8|><|sid_454|><|sid_630|><|sid_768|><|sid_end|>
  • Product B: <|sid_start|><|sid_8|><|sid_454|><|sid_599|><|sid_412|><|sid_end|>
  • Product C: <|sid_start|><|sid_8|><|sid_112|><|sid_234|><|sid_567|><|sid_end|>

A and B share first 2 levels -> Similar sub-category A and C share first 1 level -> Same broad category only

Related Resources

Citation

If you use this dataset, please cite:

@dataset{semantic_ids_video_games_with_titles,
author = {Eugene Yan},
title = {Video Games Semantic IDs with Product Titles},
year = {2024},
publisher = {Hugging Face}
}
Downloads last month
76

Models trained or fine-tuned on eugeneyan/video-games-semantic-ids-mapping