From 362279708d1b68fb012c9bf7e0ec04cb7fe78891 Mon Sep 17 00:00:00 2001 From: Adriane Boyd Date: Wed, 7 Dec 2022 15:18:59 +0100 Subject: [PATCH] Convert specifically from int32 to uint64 --- spacy/tokens/doc.pyx | 4 ++-- spacy/tokens/span.pyx | 4 ++-- spacy/training/example.pyx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index fb4d590e9..075bc4d15 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -359,7 +359,7 @@ cdef class Doc: for annot in annotations: if annot: if annot is heads or annot is sent_starts or annot is ent_iobs: - annot = numpy.array(annot).astype(numpy.uint64) + annot = numpy.array(annot, dtype=numpy.int32).astype(numpy.uint64) for i in range(len(words)): if attrs.ndim == 1: attrs[i] = annot[i] @@ -1559,7 +1559,7 @@ cdef class Doc: for j, (attr, annot) in enumerate(token_annotations.items()): if attr is HEAD: - annot = numpy.array(annot).astype(numpy.uint64) + annot = numpy.array(annot, dtype=numpy.int32).astype(numpy.uint64) for i in range(len(words)): array[i, j] = annot[i] elif attr is MORPH: diff --git a/spacy/tokens/span.pyx b/spacy/tokens/span.pyx index 1b3759128..99a5f43bd 100644 --- a/spacy/tokens/span.pyx +++ b/spacy/tokens/span.pyx @@ -299,7 +299,7 @@ cdef class Span: for ancestor in ancestors: ancestor_i = ancestor.i - self.c.start if ancestor_i in range(length): - array[i, head_col] = numpy.array(ancestor_i - i).astype(numpy.uint64) + array[i, head_col] = numpy.int32(ancestor_i - i).astype(numpy.uint64) # if there is no appropriate ancestor, define a new artificial root value = array[i, head_col] @@ -307,7 +307,7 @@ cdef class Span: new_root = old_to_new_root.get(ancestor_i, None) if new_root is not None: # take the same artificial root as a previous token from the same sentence - array[i, head_col] = numpy.array(new_root - i).astype(numpy.uint64) + array[i, head_col] = numpy.int32(new_root - i).astype(numpy.uint64) else: # set this token as the new artificial root array[i, head_col] = 0 diff --git a/spacy/training/example.pyx b/spacy/training/example.pyx index 79160bb00..95b0f0de9 100644 --- a/spacy/training/example.pyx +++ b/spacy/training/example.pyx @@ -462,7 +462,7 @@ def _annot2array(vocab, tok_annot, doc_annot): types = set([type(v) for v in value]) raise TypeError(Errors.E969.format(field=key, types=types)) from None row = [vocab.strings.add(v) for v in value] - values.append([numpy.array(v).astype(numpy.uint64) if v < 0 else v for v in row]) + values.append([numpy.array(v, dtype=numpy.int32).astype(numpy.uint64) if v < 0 else v for v in row]) array = numpy.array(values, dtype=numpy.uint64) return attrs, array.T