Prepare data directly from training samples
(self)
| 1509 | self.get_inputs() |
| 1510 | |
| 1511 | def _prepare_preference_data(self): |
| 1512 | """Prepare data directly from training samples""" |
| 1513 | matched_data = [] |
| 1514 | |
| 1515 | for sample in self.training_samples: |
| 1516 | interaction_history = sample['interaction_history'] |
| 1517 | # Skip samples without sufficient interaction history (need at least 2 items) |
| 1518 | if not interaction_history or len(interaction_history) < 2: |
| 1519 | continue |
| 1520 | |
| 1521 | # Use all items except the last one as input history |
| 1522 | # Use the last item as the target to predict |
| 1523 | input_history = interaction_history[:-1] # All but last item |
| 1524 | target_item = interaction_history[-1] # Last item as target |
| 1525 | |
| 1526 | # Create data point from each training sample |
| 1527 | row_dict = { |
| 1528 | 'user_id': sample['user_id'], |
| 1529 | 'user_preference': sample['preference_text'], |
| 1530 | 'input_history': input_history, |
| 1531 | 'target_item_id': target_item |
| 1532 | } |
| 1533 | |
| 1534 | matched_data.append(row_dict) |
| 1535 | |
| 1536 | return matched_data |
| 1537 | |
| 1538 | def _convert_to_semantic_ids(self, item_ids): |
| 1539 | """Convert item IDs to semantic ID format using index.json""" |