Spaces:
Sleeping
Sleeping
Pradeep Kumar
commited on
Delete question_answering_dataloader_test.py
Browse files
question_answering_dataloader_test.py
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
|
2 |
-
#
|
3 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
-
# you may not use this file except in compliance with the License.
|
5 |
-
# You may obtain a copy of the License at
|
6 |
-
#
|
7 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
-
#
|
9 |
-
# Unless required by applicable law or agreed to in writing, software
|
10 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
-
# See the License for the specific language governing permissions and
|
13 |
-
# limitations under the License.
|
14 |
-
|
15 |
-
"""Tests for official.nlp.data.question_answering_dataloader."""
|
16 |
-
import os
|
17 |
-
|
18 |
-
import numpy as np
|
19 |
-
import tensorflow as tf, tf_keras
|
20 |
-
|
21 |
-
from official.nlp.data import question_answering_dataloader
|
22 |
-
|
23 |
-
|
24 |
-
def _create_fake_dataset(output_path, seq_length):
|
25 |
-
"""Creates a fake dataset."""
|
26 |
-
writer = tf.io.TFRecordWriter(output_path)
|
27 |
-
|
28 |
-
def create_int_feature(values):
|
29 |
-
f = tf.train.Feature(int64_list=tf.train.Int64List(value=list(values)))
|
30 |
-
return f
|
31 |
-
|
32 |
-
for _ in range(100):
|
33 |
-
features = {}
|
34 |
-
input_ids = np.random.randint(100, size=(seq_length))
|
35 |
-
features['input_ids'] = create_int_feature(input_ids)
|
36 |
-
features['input_mask'] = create_int_feature(np.ones_like(input_ids))
|
37 |
-
features['segment_ids'] = create_int_feature(np.ones_like(input_ids))
|
38 |
-
features['start_positions'] = create_int_feature(np.array([0]))
|
39 |
-
features['end_positions'] = create_int_feature(np.array([10]))
|
40 |
-
|
41 |
-
tf_example = tf.train.Example(features=tf.train.Features(feature=features))
|
42 |
-
writer.write(tf_example.SerializeToString())
|
43 |
-
writer.close()
|
44 |
-
|
45 |
-
|
46 |
-
class QuestionAnsweringDataTest(tf.test.TestCase):
|
47 |
-
|
48 |
-
def test_load_dataset(self):
|
49 |
-
seq_length = 128
|
50 |
-
batch_size = 10
|
51 |
-
input_path = os.path.join(self.get_temp_dir(), 'train.tf_record')
|
52 |
-
_create_fake_dataset(input_path, seq_length)
|
53 |
-
data_config = question_answering_dataloader.QADataConfig(
|
54 |
-
is_training=True,
|
55 |
-
input_path=input_path,
|
56 |
-
seq_length=seq_length,
|
57 |
-
global_batch_size=batch_size)
|
58 |
-
dataset = question_answering_dataloader.QuestionAnsweringDataLoader(
|
59 |
-
data_config).load()
|
60 |
-
features, labels = next(iter(dataset))
|
61 |
-
|
62 |
-
self.assertCountEqual(['input_word_ids', 'input_mask', 'input_type_ids'],
|
63 |
-
features.keys())
|
64 |
-
self.assertEqual(features['input_word_ids'].shape, (batch_size, seq_length))
|
65 |
-
self.assertEqual(features['input_mask'].shape, (batch_size, seq_length))
|
66 |
-
self.assertEqual(features['input_type_ids'].shape, (batch_size, seq_length))
|
67 |
-
|
68 |
-
self.assertCountEqual(['start_positions', 'end_positions'], labels.keys())
|
69 |
-
self.assertEqual(labels['start_positions'].shape, (batch_size,))
|
70 |
-
self.assertEqual(labels['end_positions'].shape, (batch_size,))
|
71 |
-
|
72 |
-
|
73 |
-
if __name__ == '__main__':
|
74 |
-
tf.test.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|