Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The original code is written in keras.

Overview

CasRel-pytorch-reimplement

Pytorch reimplement of the paper "A Novel Cascade Binary Tagging Framework for Relational Triple Extraction" ACL2020. The original code was written in keras.

Requirements

  • keras-bert
  • tensorflow-gpu
  • transformers

Dataset

  • CMED: CHIP-2020 中文医学文本实体关系抽取

Usage

  1. Get the pre-trained Chinese BERT model

    1. Download the vocab.txt of BERT-wwm
    2. Get the pre-trained BERT cache
    from transformers import *
    model = BertModel.from_pretrained("hfl/chinese-bert-wwm")
    

    p.s. I use the chinese-bert-wwm here. You can also choose other pre-trained models like this

    p.p.s. the bert cache usually will be /home/your user name/.cache/torch/transformers

  2. Train the model

    python train.py
    
  3. Test the model

    python test.py
    

Results

CasRel-keras: test F1 45.59

CasRel-pytorch: test F1 47.59

You might also like...
The code for our paper
The code for our paper "NSP-BERT: A Prompt-based Zero-Shot Learner Through an Original Pre-training Task —— Next Sentence Prediction"

The code for our paper "NSP-BERT: A Prompt-based Zero-Shot Learner Through an Original Pre-training Task —— Next Sentence Prediction"

PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)
PyTorch Implementation of Fully Convolutional Networks. (Training code to reproduce the original result is available.)

pytorch-fcn PyTorch implementation of Fully Convolutional Networks. Requirements pytorch = 0.2.0 torchvision = 0.1.8 fcn = 6.1.5 Pillow scipy tqdm

Implementation of SETR model, Original paper: Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.
Implementation of SETR model, Original paper: Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.

SETR - Pytorch Since the original paper (Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.) has no official

Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

PyTorch original implementation of Cross-lingual Language Model Pretraining.
PyTorch original implementation of Cross-lingual Language Model Pretraining.

XLM NEW: Added XLM-R model. PyTorch original implementation of Cross-lingual Language Model Pretraining. Includes: Monolingual language model pretrain

The original weights of some Caffe models, ported to PyTorch.

pytorch-caffe-models This repo contains the original weights of some Caffe models, ported to PyTorch. Currently there are: GoogLeNet (Going Deeper wit

A Next Generation ConvNet by FaceBookResearch Implementation in PyTorch(Original) and TensorFlow.

ConvNeXt A Next Generation ConvNet by FaceBookResearch Implementation in PyTorch(Original) and TensorFlow. A FacebookResearch Implementation on A Conv

Original code for
Original code for "Zero-Shot Domain Adaptation with a Physics Prior"

Zero-Shot Domain Adaptation with a Physics Prior [arXiv] [sup. material] - ICCV 2021 Oral paper, by Attila Lengyel, Sourav Garg, Michael Milford and J

Comments
  • 环境配置&expected backend CUDA and dtype Float but got backend CUDA and dtype Long

    环境配置&expected backend CUDA and dtype Float but got backend CUDA and dtype Long

    我想请问一下您的cuda版本,pytorch版本,cudavision版本是什么?因为casrel本身的环境配置是tensorflow1.13.1,那么对应的cuda就是10.0,但是pytorch只有1.2以下是对应cuda10.0的,往上的版本都是对应9或者10.1,我现在运行代码的时候遇到一个问题:expected backend CUDA and dtype Float but got backend CUDA and dtype Long,网上搜到的可能的解决方法是把pytorch由1.2改为1.3,但是这样对应的cuda,tensorflow都要更改版本,所以想知道问题可能出在哪里?

    opened by Genjiz 4
  • ValueError: not enough values to unpack (expected 11, got 0)

    ValueError: not enough values to unpack (expected 11, got 0)

    您好!~打扰您了 我是NLP的初学者,很抱歉打扰您。在复现学习您的代码的过程中出现了ValueError: not enough values to unpack (expected 11, got 0)这个错误, image 我尝试输出了batch,是成功获取到值了的, image 在这个问题上困惑好几天了,我除了之前因为gdk的错误,在data_loader.py的36行左右在open函数加了encoding='UTF-8',基本没做过改动。 image 如果大佬有时间的话 如果能给我些建议和指导,万分感谢!!!!!!!!!

    opened by 2019hong 2
  • 尝试添加一层bilstm失败,求教~~

    尝试添加一层bilstm失败,求教~~

    打扰您了!在您之前的指导下我成功跑出了您readme中的结果,之后想尝试在您已有的代码的基础上在头实体编码的地方,在bert后再接一层bilstm,但失败了。我的所有值都为0. image 我添加的方式是: image 是不能直接那么连接吗?还是我应该对后续的所有计算都进行调整?还是什么其他要学习和理解的地方?我现在有点没有头绪,给您添麻烦了,如果可以期待能获得您的指导和建议~~~

    opened by 2019hong 0
  • loss计算中的bug

    loss计算中的bug

    framework.py文件中,存在以下bug:

    if los.shape != mask.shape:
    mask= mask.unsqueeze(dim=-1) #应该加入该行代码,否则在后续求loss均值时,torch.sum(input_masks), 计算的总数个数不齐全 mask= mask.repeat((1, 1, loss.size(2)))

    opened by yuanshengjun 0
Owner
longlongman
longlongman
The repo contains the code of the ACL2020 paper `Dice Loss for Data-imbalanced NLP Tasks`

Dice Loss for NLP Tasks This repository contains code for Dice Loss for Data-imbalanced NLP Tasks at ACL2020. Setup Install Package Dependencies The c

null 223 Dec 17, 2022
Reimplementation of the paper `Human Attention Maps for Text Classification: Do Humans and Neural Networks Focus on the Same Words? (ACL2020)`

Human Attention for Text Classification Re-implementation of the paper Human Attention Maps for Text Classification: Do Humans and Neural Networks Foc

Shunsuke KITADA 15 Dec 13, 2021
Codebase for the Summary Loop paper at ACL2020

Summary Loop This repository contains the code for ACL2020 paper: The Summary Loop: Learning to Write Abstractive Summaries Without Examples. Training

Canny Lab @ The University of California, Berkeley 44 Nov 4, 2022
Script that receives an Image (original) and a set of images to be used as "pixels" in reconstruction of the Original image using the set of images as "pixels"

picinpics Script that receives an Image (original) and a set of images to be used as "pixels" in reconstruction of the Original image using the set of

RodrigoCMoraes 1 Oct 24, 2021
Cross-media Structured Common Space for Multimedia Event Extraction (ACL2020)

Cross-media Structured Common Space for Multimedia Event Extraction Table of Contents Overview Requirements Data Quickstart Citation Overview The code

Manling Li 49 Nov 21, 2022
Home repository for the Regularized Greedy Forest (RGF) library. It includes original implementation from the paper and multithreaded one written in C++, along with various language-specific wrappers.

Regularized Greedy Forest Regularized Greedy Forest (RGF) is a tree ensemble machine learning method described in this paper. RGF can deliver better r

RGF-team 364 Dec 28, 2022
This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras)

Yogi-Optimizer_Keras This is an implementation of Googles Yogi-Optimizer in Keras (tf.keras) The NeurIPS-Paper can be found here: http://papers.nips.c

null 14 Sep 13, 2022
Keras udrl - Keras implementation of Upside Down Reinforcement Learning

keras_udrl Keras implementation of Upside Down Reinforcement Learning This is me

Eder Santana 7 Jan 24, 2022
Example-custom-ml-block-keras - Custom Keras ML block example for Edge Impulse

Custom Keras ML block example for Edge Impulse This repository is an example on

Edge Impulse 8 Nov 2, 2022
Classification models 1D Zoo - Keras and TF.Keras

Classification models 1D Zoo - Keras and TF.Keras This repository contains 1D variants of popular CNN models for classification like ResNets, DenseNet

Roman Solovyev 12 Jan 6, 2023