huggingface / huggingface/neuralcoref

Train Neuralcoref in new language

Open
#321 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
2.9k
Forks
467
PR merge metrics
No merged PRs in 30d

Description

Hi :), I want train Neuralcoref in language Spanish. First I try train Neuralcoref in English, I get a corpus with format *.v4_gold_conll from this url: **https://github.com/clab/att-coref/tree/master/data/conll-2012**
Then I saves this files in the folders train, test and dev.

With the scripts Conllparser.py and learn.py, I process the data and trained.

I get three files from this training:

- Jul25_22-52-53_95e13715414b_best_modelallpairs
- Jul25_22-52-53_95e13715414b_best_modelranking
- Jul25_22-52-53_95e13715414b_best_modeltoppairs

This files are weights and bias from the models trained.

I want use this models, but I don't know how. I try this, but I get error.:

```
import torch

tm = torch.load('./Jul25_22-52-53_95e13715414b_best_modelallpairs')

SIZE_SINGLE_IN=674
SIZE_PAIR_IN=1370
h1=1000
h2=h3=500

from thinc.v2v import Model, ReLu, Affine
from thinc.api import chain, clone

with Model.define_operators({'**': clone, '>>': chain}):
single_model = ReLu(h1, SIZE_SINGLE_IN) >> ReLu(h2, h1) >> ReLu(h3, h2) >> Affine(1, h3) >> Affine(1, 1)
pairs_model = ReLu(h1, SIZE_PAIR_IN) >> ReLu(h2, h1) >> ReLu(h3, h2) >> Affine(1, h3) >> Affine(1, 1)

for l in pairs_model._layers + single_model._layers:
l.W
l.b

pairs_model._layers[0].W = tm["pair_top.0.weight"].cpu().numpy()
pairs_model._layers[0].b = tm["pair_top.0.bias"].cpu().numpy()

pairs_model._layers[1].W = tm["pair_top.3.weight"].cpu().numpy()
pairs_model._layers[1].b = tm["pair_top.3.bias"].cpu().numpy()

pairs_model._layers[2].W = tm["pair_top.6.weight"].cpu().numpy()
pairs_model._layers[2].b = tm["pair_top.6.bias"].cpu().numpy()

pairs_model._layers[3].W = tm["pair_top.9.weight"].cpu().numpy()
pairs_model._layers[3].b = tm["pair_top.9.bias"].cpu().numpy()

pairs_model._layers[4].W = tm["pair_top.10.weight"].cpu().numpy()
pairs_model._layers[4].b = tm["pair_top.10.bias"].cpu().numpy()

single_model._layers[0].W = tm["single_top.0.weight"].cpu().numpy()
single_model._layers[0].b = tm["single_top.0.bias"].cpu().numpy()

single_model._layers[1].W = tm["single_top.3.weight"].cpu().numpy()
single_model._layers[1].b = tm["single_top.3.bias"].cpu().numpy()

single_model._layers[2].W = tm["single_top.6.weight"].cpu().numpy()
single_model._layers[2].b = tm["single_top.6.bias"].cpu().numpy()

single_model._layers[3].W = tm["single_top.9.weight"].cpu().numpy()
single_model._layers[3].b = tm["single_top.9.bias"].cpu().numpy()

single_model._layers[4].W = tm["single_top.10.weight"].cpu().numpy()
single_model._layers[4].b = tm["single_top.10.bias"].cpu().numpy()

import spacy
nlp = spacy.load("en_core_web_md")
print(nlp.vocab)
import neuralcoref
nc = neuralcoref.NeuralCoref(nlp.vocab)
nc.model = single_model, pairs_model
nlp.add_pipe(nc, "neuralcoref")
doc = nlp('My sister has a dog. She loves him.')

print('1 ',doc)
print('2',doc._.has_coref)
print('3',doc._.coref_clusters)
```

The error is:

```
File "/usr/local/lib/python3.8/dist-packages/thinc/check.py", line 74, in has_shape_inner
raise ShapeMismatchError(arg.shape, shape_values, shape)
thinc.exceptions.ShapeMismatchError:

Shape mismatch: input (4, 668) not compatible with [None, 674].

Traceback:
├─ __call__ in /usr/local/lib/python3.8/dist-packages/spacy/language.py:385
├─── __call__ in neural/_classes/model.py:167
└───── predict in neural/_classes/feed_forward.py:40
>>> X = layer(X)

```

Something it's wrong.

How I Can load this three models in spacy?

Note: spacy==2.1.3 ; neuralcoref=4.0 ; torch=1.7.1+cu101

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.