Giter Site home page Giter Site logo

rpbert-gcn-ner's Introduction

GCN-RpBert

This is an implementation of the RpBERT paper: RpBERT: A Text-image Relation Propagation-based BERT Model for Multimodal NER, With a additional layer of GCN added in between the bert-resnet encode layer and the Bi-LSTM layer.

Original Code (without the GCN layer) from MultiModel-NER/RpBERT Repo.

The dataset has already been installed. Also torchcrf is already in the directory, since for some reason, PIP kept downloading the crf package instead of the torch-crf package even thought I entered pip install torch-crf.

Warning

This repository is still under development, if there are any questions, feel free to just start and issue.

The cuda support is turned off. But if you want to turn it on, it is in the file model.py. Find this code snippet in the class MultimodelModel and switch the code:

...
    @classmethod
    def from_pretrained(cls, cuda, t_encoder, v_encoder):
        device = torch.device(f'cpu')
        #device = torch.device(f"cuda:{cuda}")
        models_path = '../resources/models'

        encoder_t_path = f'{models_path}/transformers/{t_encoder}'
        tokenizer = AutoTokenizer.from_pretrained(encoder_t_path)
        encoder_t = AutoModel.from_pretrained(encoder_t_path)
        config = AutoConfig.from_pretrained(encoder_t_path)
        hid_dim_t = config.hidden_size


        encoder_v = getattr(torchvision.models, v_encoder)()
        encoder_v.load_state_dict(torch.load(f'{models_path}/cnn/{v_encoder}.pth'))
        hid_dim_v = encoder_v.fc.in_features
...

Instructions

Installing

Install the packages in requirements.txt

Downloading Resnet152

run the following code:

import torchvision
resnet152_model = torchvision.models.resnet152(from_pretrained=True)

Copy the resnet152.pth model under the directory resources/models/cnn after it finished downloading. It should be in the path C:/Users/Administrator/.resnet152/weights for windows.

Downloading Bert-Base-Uncased

Dowload via link: Bert-Base-Uncased. Unzip the package into a dir, and move it under the directory resources/models/transformers. After moving it to the directory resources/models/transformers, download the pytorch_model.bin and config.json manually into the directory from the bert-base-uncased hugginface page.

Downloading the dataset

The twitter2015 paper: (Zhang et al., 2018).

The dataset need to downloaded and unziped. Then change the name into "twitter2015". Then go into the directory and change the directory containing all the images to "images". After all this, move the directory under the path: resources/dataset.

Training

To train, run train.py. An example on how to run the model is at the file main.py

rpbert-gcn-ner's People

Contributors

ivanhe123 avatar

Watchers

Kostas Georgiou avatar  avatar

Forkers

liusenling

rpbert-gcn-ner's Issues

Displays empty during validation

Hello, have you ever encountered ValueError: max() arg is an empty sequence when you run it?
Traceback (most recent call last):
File "train1.py", line 70, in
dev_f1, dev_report = evaluate(model, ner_dev_loader)
File "/root/autodl-fs/RpBERT-GCN-NER-main/utils.py", line 56, in evaluate
report = classification_report(true_labels, pred_labels, digits=4, mode='strict', scheme=IOB2)
File "/root/miniconda3/lib/python3.8/site-packages/seqeval/metrics/sequence_labeling.py", line 670, in classification_report
return cr(y_true, y_pred,
File "/root/miniconda3/lib/python3.8/site-packages/seqeval/metrics/v1.py", line 390, in classification_report
name_width = max(map(len, target_names))
ValueError: max() arg is an empty sequence.

维度不匹配

RuntimeError: The size of tensor a (514) must match the size of tensor b (512) at non-singleton dimension 1

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.