Tidy up and avoid absolute spacy imports in core

This commit is contained in:
Ines Montani 2020-05-21 20:05:03 +02:00
parent c6ec19c844
commit 0f1beb5ff2
4 changed files with 10 additions and 20 deletions

View File

@ -2,7 +2,6 @@
from __future__ import unicode_literals, division, print_function from __future__ import unicode_literals, division, print_function
import plac import plac
import spacy
from timeit import default_timer as timer from timeit import default_timer as timer
from wasabi import msg from wasabi import msg
@ -45,7 +44,7 @@ def evaluate(
msg.fail("Visualization output directory not found", displacy_path, exits=1) msg.fail("Visualization output directory not found", displacy_path, exits=1)
corpus = GoldCorpus(data_path, data_path) corpus = GoldCorpus(data_path, data_path)
if model.startswith("blank:"): if model.startswith("blank:"):
nlp = spacy.blank(model.replace("blank:", "")) nlp = util.get_lang_class(model.replace("blank:", ""))()
else: else:
nlp = util.load_model(model) nlp = util.load_model(model)
dev_docs = list(corpus.dev_docs(nlp, gold_preproc=gold_preproc)) dev_docs = list(corpus.dev_docs(nlp, gold_preproc=gold_preproc))

View File

@ -6,7 +6,7 @@ from libcpp.vector cimport vector
from libc.stdint cimport int32_t, int64_t from libc.stdint cimport int32_t, int64_t
from libc.stdio cimport FILE from libc.stdio cimport FILE
from spacy.vocab cimport Vocab from .vocab cimport Vocab
from .typedefs cimport hash_t from .typedefs cimport hash_t
from .structs cimport KBEntryC, AliasC from .structs cimport KBEntryC, AliasC
@ -169,4 +169,3 @@ cdef class Reader:
cdef int read_alias(self, int64_t* entry_index, float* prob) except -1 cdef int read_alias(self, int64_t* entry_index, float* prob) except -1
cdef int _read(self, void* value, size_t size) except -1 cdef int _read(self, void* value, size_t size) except -1

View File

@ -1,23 +1,20 @@
# cython: infer_types=True # cython: infer_types=True
# cython: profile=True # cython: profile=True
# coding: utf8 # coding: utf8
import warnings
from spacy.errors import Errors, Warnings
from pathlib import Path
from cymem.cymem cimport Pool from cymem.cymem cimport Pool
from preshed.maps cimport PreshMap from preshed.maps cimport PreshMap
from cpython.exc cimport PyErr_SetFromErrno from cpython.exc cimport PyErr_SetFromErrno
from libc.stdio cimport fopen, fclose, fread, fwrite, feof, fseek from libc.stdio cimport fopen, fclose, fread, fwrite, feof, fseek
from libc.stdint cimport int32_t, int64_t from libc.stdint cimport int32_t, int64_t
from libcpp.vector cimport vector
import warnings
from os import path
from pathlib import Path
from .typedefs cimport hash_t from .typedefs cimport hash_t
from os import path from .errors import Errors, Warnings
from libcpp.vector cimport vector
cdef class Candidate: cdef class Candidate:
@ -586,5 +583,3 @@ cdef class Reader:
cdef int _read(self, void* value, size_t size) except -1: cdef int _read(self, void* value, size_t size) except -1:
status = fread(value, size, 1, self._fp) status = fread(value, size, 1, self._fp)
return status return status

View File

@ -4,10 +4,7 @@ from __future__ import absolute_import, unicode_literals
import random import random
import itertools import itertools
import warnings import warnings
from thinc.extra import load_nlp from thinc.extra import load_nlp
from spacy.util import minibatch
import weakref import weakref
import functools import functools
from collections import OrderedDict from collections import OrderedDict
@ -852,7 +849,7 @@ class Language(object):
*[mp.Pipe(False) for _ in range(n_process)] *[mp.Pipe(False) for _ in range(n_process)]
) )
batch_texts = minibatch(texts, batch_size) batch_texts = util.minibatch(texts, batch_size)
# Sender sends texts to the workers. # Sender sends texts to the workers.
# This is necessary to properly handle infinite length of texts. # This is necessary to properly handle infinite length of texts.
# (In this case, all data cannot be sent to the workers at once) # (In this case, all data cannot be sent to the workers at once)