Randomly samples from train set :param train: the train set :param n_samples: the num of samples :return: a list of samples
(train: Dict, n_samples=1)
| 13 | |
| 14 | |
| 15 | def get_random_samples(train: Dict, n_samples=1) -> List[Dict]: |
| 16 | """ |
| 17 | Randomly samples from train set |
| 18 | |
| 19 | :param train: the train set |
| 20 | :param n_samples: the num of samples |
| 21 | :return: a list of samples |
| 22 | """ |
| 23 | if n_samples > len(train): |
| 24 | raise ValueError("n_samples should be less than or equal to len(train)") |
| 25 | |
| 26 | # random n sample |
| 27 | samples = random.sample(list(train.values()), n_samples) |
| 28 | |
| 29 | return samples |
| 30 | |
| 31 | |
| 32 | def get_similar_text_embed_by_knn(train: Dict, text: str, model='transformer', n_samples=1) -> List[Dict]: |
no test coverage detected