fetches a random sentencepair corresponding to rng state similar to https://github.com/google-research/bert/blob/master/create_pretraining_data.py#L248-L294
(self, target_seq_length, rng, np_rng)
| 949 | return rtn |
| 950 | |
| 951 | def create_random_sentencepair(self, target_seq_length, rng, np_rng): |
| 952 | """ |
| 953 | fetches a random sentencepair corresponding to rng state similar to |
| 954 | https://github.com/google-research/bert/blob/master/create_pretraining_data.py#L248-L294 |
| 955 | """ |
| 956 | is_random_next = None |
| 957 | |
| 958 | curr_strs = [] |
| 959 | curr_str_types = [] |
| 960 | curr_len = 0 |
| 961 | |
| 962 | while curr_len < 1: |
| 963 | curr_len = 0 |
| 964 | doc_a = None |
| 965 | while doc_a is None: |
| 966 | if self.weighted: |
| 967 | # doc_a_idx = np_rng.choice(self.ds_len, p=self.weighting) |
| 968 | doc_a_idx = self.get_weighted_samples(np_rng) |
| 969 | else: |
| 970 | doc_a_idx = rng.randint(0, self.ds_len - 1) |
| 971 | doc_a = self.sentence_split(self.get_doc(doc_a_idx)) |
| 972 | if not doc_a: |
| 973 | doc_a = None |
| 974 | |
| 975 | random_start_a = rng.randint(0, len(doc_a) - 1) |
| 976 | while random_start_a < len(doc_a): |
| 977 | sentence = doc_a[random_start_a] |
| 978 | sentence, sentence_types = self.sentence_tokenize(sentence, 0, random_start_a == 0, |
| 979 | random_start_a == len(doc_a)) |
| 980 | curr_strs.append(sentence) |
| 981 | curr_str_types.append(sentence_types) |
| 982 | curr_len += len(sentence) |
| 983 | if random_start_a == len(doc_a) - 1 or curr_len >= target_seq_length: |
| 984 | break |
| 985 | random_start_a = (random_start_a + 1) |
| 986 | |
| 987 | if curr_strs: |
| 988 | num_a = 1 |
| 989 | if len(curr_strs) >= 2: |
| 990 | num_a = rng.randint(0, len(curr_strs)) |
| 991 | |
| 992 | tokens_a = [] |
| 993 | token_types_a = [] |
| 994 | for j in range(num_a): |
| 995 | tokens_a.extend(curr_strs[j]) |
| 996 | token_types_a.extend(curr_str_types[j]) |
| 997 | |
| 998 | tokens_b = [] |
| 999 | token_types_b = [] |
| 1000 | is_random_next = False |
| 1001 | if len(curr_strs) == 1 or rng.random() < 0.5: |
| 1002 | is_random_next = True |
| 1003 | target_b_length = target_seq_length - len(tokens_a) |
| 1004 | b_len = 0 |
| 1005 | while b_len < 1: |
| 1006 | doc_b = None |
| 1007 | while doc_b is None: |
| 1008 | doc_b_idx = rng.randint(0, self.ds_len - 2) |
no test coverage detected