MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / __init__

Method __init__

ts_rec_data.py:424–482  ·  view source on GitHub ↗

Fusion dataset combining sequence recommendation with item features. Uses semantic IDs for user history, outputs item titles or descriptions. Args: train_file: Path to CSV file with sequence data item_file: Path to .item.json file with item f

(self, train_file, item_file, index_file, tokenizer, max_len=2048, sample=-1, test=False, seed=0, category="", dedup=False)

Source from the content-addressed store, hash-verified

422
423class FusionSeqRecDataset(Dataset):
424 def __init__(self, train_file, item_file, index_file, tokenizer, max_len=2048, sample=-1, test=False, seed=0, category="", dedup=False):
425 """
426 Fusion dataset combining sequence recommendation with item features.
427 Uses semantic IDs for user history, outputs item titles or descriptions.
428
429 Args:
430 train_file: Path to CSV file with sequence data
431 item_file: Path to .item.json file with item features
432 index_file: Path to .index.json file with item indices
433 tokenizer: Tokenizer for encoding text
434 max_len: Maximum sequence length
435 sample: Number of samples to use (-1 for all)
436 test: Whether this is test mode
437 seed: Random seed
438 category: Category name for prompts
439 dedup: Whether to filter duplicate items
440 """
441 random.seed(seed)
442
443 # Load sequence data
444 self.data = pd.read_csv(train_file)
445 if sample > 0:
446 self.data = self.data.sample(sample, random_state=seed)
447
448 # Load item features and indices
449 with open(item_file, 'r') as f:
450 self.item_feat = json.load(f)
451 with open(index_file, 'r') as f:
452 self.indices = json.load(f)
453
454 self.tokenizer = Tokenizer(tokenizer)
455 self.test = test
456 self.max_len = max_len
457 self.category = category
458 self.dedup = dedup
459
460 # Build sid2title and sid2description mappings
461 self.sid2title = {}
462 self.sid2description = {}
463
464 for item_id, sids in self.indices.items():
465 if item_id in self.item_feat:
466 title = self.item_feat[item_id]['title']
467 description = self.item_feat[item_id]['description']
468
469 # Process description according to requirements:
470 # 1. If description is empty, use title
471 # 2. If description is a list, select the longest one
472 # 3. If the longest in list is also empty, use title
473 processed_description = self._process_description(description, title)
474
475 # Concatenate all three semantic IDs as the key
476 if len(sids) >= 3:
477 combined_sid = sids[0] + sids[1] + sids[2]
478 self.sid2title[combined_sid] = title
479 self.sid2description[combined_sid] = processed_description
480 # print("self.sid2title: ", self.sid2title)
481 # print("self.sid2description: ", self.sid2description)

Callers

nothing calls this directly

Calls 3

_process_descriptionMethod · 0.95
get_inputsMethod · 0.95
TokenizerClass · 0.70

Tested by

no test coverage detected