Skip to content

Commit 367e219

Browse files
hawkinsptensorflow-copybara
authored andcommitted
[NumPy] Remove references to deprecated NumPy type aliases.
This change replaces references to a number of deprecated NumPy type aliases (np.bool, np.int, np.float, np.complex, np.object, np.str) with their recommended replacement (bool, int, float, complex, object, str). NumPy 1.24 drops the deprecated aliases, so we must remove uses before updating NumPy. PiperOrigin-RevId: 496402381
1 parent 0cc2190 commit 367e219

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

research/a2n/dataset.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_graph_nbrhd(train_graph, ent, exclude_tuple):
3636
# er not in train_graph.reverse_kg_data[ent][nbr]]
3737
(train_graph.reverse_kg_data[ent][nbr] - set([er]))]
3838
neighborhood += rev_nighborhood
39-
neighborhood = np.array(list(set(neighborhood)), dtype=np.int)
39+
neighborhood = np.array(list(set(neighborhood)), dtype=int)
4040
return neighborhood
4141

4242

@@ -55,7 +55,7 @@ def get_graph_nbrhd_with_rels(train_graph, ent, exclude_tuple):
5555
# # er not in train_graph.reverse_kg_data[ent][nbr]]
5656
# (train_graph.reverse_kg_data[ent][nbr] - set([er]))]
5757
# neighborhood += rev_nighborhood
58-
neighborhood = np.array(neighborhood, dtype=np.int)
58+
neighborhood = np.array(neighborhood, dtype=int)
5959
return neighborhood
6060

6161

@@ -78,7 +78,7 @@ def get_graph_nbrhd_text(train_graph, ent, max_text_len):
7878
# # er not in train_graph.reverse_kg_data[ent][nbr]]
7979
# (train_graph.reverse_kg_data[ent][nbr] - set([er]))]
8080
# neighborhood += rev_nighborhood
81-
neighborhood = np.array(neighborhood, dtype=np.int)
81+
neighborhood = np.array(neighborhood, dtype=int)
8282
return neighborhood
8383

8484

@@ -94,7 +94,7 @@ def get_graph_nbrhd_embd_text(train_graph, ent, max_text_nbrs):
9494
if not neighborhood:
9595
neighborhood = [[]]
9696
neighborhood_emb = [np.zeros(train_graph.embeddings[0].size)]
97-
neighborhood = np.array(neighborhood, dtype=np.int)
97+
neighborhood = np.array(neighborhood, dtype=int)
9898
neighborhood_emb = np.array(neighborhood_emb, dtype=np.float32)
9999
if neighborhood.shape[0] > max_text_nbrs:
100100
ids = np.random.choice(np.range(neighborhood.shape[0]),
@@ -162,7 +162,7 @@ def get_graph_nbrhd_paths(train_graph, ent, exclude_tuple):
162162
neighborhood += paths
163163
if not neighborhood:
164164
neighborhood = [[]]
165-
neighborhood = np.array(neighborhood, dtype=np.int)
165+
neighborhood = np.array(neighborhood, dtype=int)
166166
return neighborhood
167167

168168

@@ -223,7 +223,7 @@ def get_graph_nbrhd_paths_randwalk(train_graph, ent, exclude_tuple,
223223
if not neighborhood:
224224
neighborhood = [[]]
225225
# import pdb; pdb.set_trace()
226-
neighborhood = np.array(neighborhood, dtype=np.int)
226+
neighborhood = np.array(neighborhood, dtype=int)
227227
return neighborhood
228228

229229

@@ -354,7 +354,7 @@ def featurize_each_example(self, example_tuple):
354354
# else:
355355
# negatives = np.array(candidate_negatives)
356356
negatives = sample_or_pad(
357-
np.array(candidate_negatives, dtype=np.int), self.max_negatives,
357+
np.array(candidate_negatives, dtype=int), self.max_negatives,
358358
pad_value=self.train_graph.ent_pad
359359
)
360360
# negatives is an array of shape (max_negatives)
@@ -377,8 +377,8 @@ def featurize_each_example(self, example_tuple):
377377
nbrhd_fn = get_graph_nbrhd
378378
pad_value = self.train_graph.ent_pad
379379
if self.model_type == "distmult":
380-
nbrs_s = np.array([], dtype=np.int)
381-
nbrs_candidates = np.array([], dtype=np.int)
380+
nbrs_s = np.array([], dtype=int)
381+
nbrs_candidates = np.array([], dtype=int)
382382
elif self.model_type in ["source_attention", "source_rel_attention",
383383
"source_path_attention"]:
384384
nbrs_s = sample_or_pad(nbrhd_fn(self.train_graph, s, (s, r, t)),
@@ -396,7 +396,7 @@ def featurize_each_example(self, example_tuple):
396396
get_graph_nbrhd_text(self.train_graph, s, self.max_text_len),
397397
self.max_text_neighbors, pad_value=text_pad_value
398398
)
399-
nbrs_candidates = np.array([], dtype=np.int)
399+
nbrs_candidates = np.array([], dtype=int)
400400
else:
401401
nbrs_s = sample_or_pad(nbrhd_fn(self.train_graph, s, (s, r, t)),
402402
self.max_neighbors,
@@ -417,7 +417,7 @@ def featurize_each_example(self, example_tuple):
417417
if self.mode != "train":
418418
labels = [t]
419419
else:
420-
labels = np.zeros(candidates.shape[0], dtype=np.int)
420+
labels = np.zeros(candidates.shape[0], dtype=int)
421421
labels[0] = 1
422422
idx = np.arange(candidates.shape[0])
423423
np.random.shuffle(idx)

research/gam/gam/data/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def __init__(self, dataset, keep_label_proportions=False, inductive=False):
669669
labeled_indices = list(self.get_indices_train())
670670
labeled_indices_labels = dataset.get_labels(labeled_indices)
671671
label_counts = collections.Counter(labeled_indices_labels)
672-
num_labels = np.float(len(labeled_indices))
672+
num_labels = float(len(labeled_indices))
673673
assert num_labels > 0, 'There are no labeled samples in the dataset.'
674674
self.label_prop = {
675675
label: count / num_labels for label, count in label_counts.items()

research/gam/gam/data/loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def load_data_realistic_ssl(dataset_name, data_path, label_map_path):
9494
train_indices = np.asarray(train_indices)
9595

9696
# Select the loaded train indices, and make the rest unlabeled.
97-
unlabeled_mask = np.ones((train_inputs.shape[0],), dtype=np.bool)
97+
unlabeled_mask = np.ones((train_inputs.shape[0],), dtype=bool)
9898
unlabeled_mask[train_indices] = False
9999
unlabeled_inputs = train_inputs[unlabeled_mask]
100100
unlabeled_labels = train_labels[unlabeled_mask]
@@ -159,7 +159,7 @@ def _sample_mask(idx, l):
159159
"""Create mask."""
160160
mask = np.zeros(l)
161161
mask[idx] = 1
162-
return np.array(mask, dtype=np.bool)
162+
return np.array(mask, dtype=bool)
163163

164164
def _parse_index_file(filename):
165165
"""Parse index file."""

0 commit comments

Comments
 (0)