Code Monkey home page Code Monkey logo

Comments (13)

yhcc avatar yhcc commented on June 23, 2024 1

I will try to give you a demo recently.

from tener.

TorRient avatar TorRient commented on June 23, 2024

I will try to give you a demo recently.

i waiting for you
thank you so much

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

Hello,

First and foremost I hope this email finds you well. I need to test this model. Can you please send this to me as well? The input type is str. It is really important to me.

from tener.

yhcc avatar yhcc commented on June 23, 2024

Sorry, since the last issue has been closed, I forgot to give the demo later.
code to add in the training file: https://github.com/fastnlp/TENER/blob/master/train_tener_en.py

# before this line https://github.com/fastnlp/TENER/blob/d2614d509dffb9b30636e3523a2f8f0dc4876708/train_tener_en.py#L101 add the following code to save the vocabulary for later usage
data_bundle.get_vocab('chars').save('/path/to/save/vocab.txt')
data_bundle.get_vocab('target').save('/path/to/save/target.txt')
# change save_path=None in https://github.com/fastnlp/TENER/blob/d2614d509dffb9b30636e3523a2f8f0dc4876708/train_tener_en.py#L123 to save_path='directory/to/save/model/', this will save a model in this directory
import torch
from fastNLP import Vocabulary

model = torch.load('/path/to/your/model')  # I assume you use the Trainer save_path parameter to save the model in whole, you can find a file in the directory you pointed during training and that is the saved model.

vocab = Vocabulary.load('/path/to/save/vocab.txt')
target_vocab = Vocabulary.load('/path/to/save/target_vocab.txt')

text = "China is a country".split()  # I use this simple text as an example
indices = torch.LongTensor([vocab.to_index(w) for w in text]).unsqueeze(0)  # change to indices, and add a batch dimension

targets = model.predict(indices)  # will be of shape [1, 5]
targets = targets[0].tolist()
targets = [target_vocab.to_word(t) for t in targets]  # will be like ['S-ORG', 'O', 'O', ...]

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

Thank you very much for providing the Demo. I have a question: Should I train it again?

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

Also how can I save my model? Because you said # I assume you use the Trainer save_path parameter to save the model in whole, otherwise, you need to initialize your model then load the weights.

from tener.

yhcc avatar yhcc commented on June 23, 2024

Sorry, i did not understand what do you mean by "Should I train it again ?".
For "how can i save my model ?", i assume you are asking how to save the model in pytorch, here is the refrence https://pytorch.org/docs/stable/torch.html#torch.save

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

It says that I need permission when I run the code above. Also, the model.pt is a directory. Is that normal?

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

Can you please send the model.pt because my model.pt is not a file but it is a folder.

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

It says Permission Denied. I am using windows and I tried to launch it as administrator.

from tener.

yhcc avatar yhcc commented on June 23, 2024

Sorry, I didn't save my model. And sorry for the mistake I made, you need to load 'model.pt/xxxx' (xxxx is what in your directory, that is the model). I forgot that the save_path parameter in Trainer is pointing a directory to save the model (Trainer will assign a name to the saved model by timestamp).

from tener.

7228TigersFan avatar 7228TigersFan commented on June 23, 2024

It gives an error:
No module named 'models'

from tener.

yhcc avatar yhcc commented on June 23, 2024

It seems like that you are using the model outside the folder where you trained your model, in this case, model has to been saved by parameters. Right now, fastNLP does not support save and load trained model very well (I am working on these stuff, but it may take some time to finish), therefore, if you want to save the model for later use, the only help this repo can provide right now is a reference to the implementation of the model. Sorry for the inconvenience, as long as i finish coding the fastNLP part, i will update this issue.

from tener.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.