Prepare sequence prediction data from training samples
(self)
| 1692 | self.get_inputs() |
| 1693 | |
| 1694 | def _prepare_sequence_data(self): |
| 1695 | """Prepare sequence prediction data from training samples""" |
| 1696 | matched_data = [] |
| 1697 | |
| 1698 | for sample in self.training_samples: |
| 1699 | interaction_history = sample['interaction_history'] |
| 1700 | |
| 1701 | # Skip samples without sufficient interaction history (need at least 2 items) |
| 1702 | if not interaction_history or len(interaction_history) < 2: |
| 1703 | continue |
| 1704 | |
| 1705 | # Use all items except the last one as input history |
| 1706 | # Use the last item as the target to predict |
| 1707 | input_history = interaction_history[:-1] # All but last item |
| 1708 | target_item = interaction_history[-1] # Last item as target |
| 1709 | |
| 1710 | row_dict = { |
| 1711 | 'user_id': sample['user_id'], |
| 1712 | 'user_preference': sample['preference_text'], |
| 1713 | 'input_history': input_history, |
| 1714 | 'target_item_id': target_item |
| 1715 | } |
| 1716 | |
| 1717 | matched_data.append(row_dict) |
| 1718 | |
| 1719 | return matched_data |
| 1720 | |
| 1721 | def _convert_to_semantic_ids(self, item_ids): |
| 1722 | """Convert item IDs to semantic ID format using index.json""" |