Relation Classification with Entity Type Restriction

该论文提出了一种简单但有效的方法,通过实体类型限制来减少关系分类的候选关系,从而提高模型性能。在两个代表性模型上实验,结果显示这种方法能显著提升关系分类的准确率,分别比GCN和SpanBERT高出6.9%和4.4%。

这是一篇ACL Findings的论文,idea很简单,但却非常奏效。

关系分类旨在预测句子中两个实体间的关系,这篇论文通过实体类型来限制关系的搜索范围。例如两个实体类型都是person,那么他们的关系就可以排除出生地,这样就能减少候选关系的数量:

example

模型结构

model

算法流程

algorithm

R(ts,to)={r∈R∣(s,o)∈Dr}={r∈R∣ts∈S(r) and  to ∈O(r)} \begin{aligned} R_{(t s, t o)} &=\left\{r \in R \mid(s, o) \in D_{r}\right\} \\ &=\{r \in R \mid t s \in S(r) \text { and } \text { to } \in O(r)\} \end{aligned} R(ts,to)={rR(s,o)Dr}={rRtsS(r) and  to O(r)}

  1. 首先根据句子中实体的类型将句子归好组
  2. 对于每一组,收集所有关系组成一个集合 R(ts,to)R_{(t s, t o)}R(ts,to)
  3. 针对该关系集合学习一个分类器 fgf_gfg

实验结果

由于该方法是模型无关的,所以作者在两个代表性模型上做了实验:

result

RECENT 分别比 GCNSpanBERT 高了6.9和4.4,提升还是非常明显的。


Cite

@inproceedings{lyu-chen-2021-relation,
    title = "Relation Classification with Entity Type Restriction",
    author = "Lyu, Shengfei and Chen, Huanhuan",
    booktitle = "Findings of the Association for Computational Linguistics: ACL-IJCNLP 2021",
    month = aug,
    year = "2021",
    address = "Online",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.findings-acl.34",
    doi = "10.18653/v1/2021.findings-acl.34",
    pages = "390--395",
}
### 如何复现 Attention-Based Bidirectional LSTM Networks for Relation Classification #### 准备工作 为了成功复现基于注意力机制的双向长短期记忆网络(Att-BLSTM)用于关系分类的任务,需准备必要的环境和数据集。确保安装了Python以及常用的机器学习库如TensorFlow或PyTorch等框架。 #### 数据预处理 首先加载并清理训练所需的数据集。这通常涉及去除无关字符、分词、转换大小写等工作。对于每个样本中的词语,利用预先训练好的词向量模型将其转化为固定长度的向量表示形式[^3]。 ```python import numpy as np from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences def preprocess_data(texts, labels=None): tokenizer = Tokenizer(num_words=MAX_NB_WORDS) tokenizer.fit_on_texts(texts) sequences = tokenizer.texts_to_sequences(texts) word_index = tokenizer.word_index data = pad_sequences(sequences, maxlen=MAX_SEQUENCE_LENGTH) if labels is not None: label_encoder = LabelEncoder() encoded_labels = label_encoder.fit_transform(labels) return data, encoded_labels, word_index else: return data, word_index ``` #### 构建模型架构 构建包含五个主要组件的神经网络结构:输入层、嵌入层、双向LSTM层、注意层层及输出层。这里采用Keras API来定义这一复杂的深度学习模型[^4]。 ```python from tensorflow.keras.models import Model from tensorflow.keras.layers import Input, Embedding, Bidirectional, LSTM, Dense, Dropout, concatenate, Attention embedding_layer = Embedding(input_dim=vocab_size, output_dim=EMBEDDING_DIM, weights=[embedding_matrix], input_length=max_len, trainable=False) sequence_input = Input(shape=(max_len,), dtype='int32') embedded_sequences = embedding_layer(sequence_input) l_lstm = Bidirectional(LSTM(units=LSTM_UNITS, return_sequences=True))(embedded_sequences) attention_output = Attention()([l_lstm, l_lstm]) dense_1 = Dense(DENSE_UNITS, activation="relu")(attention_output) dropout_1 = Dropout(rate=DROPOUT_RATE)(dense_1) output = Dense(len(label_names), activation='softmax')(dropout_1) model = Model(inputs=sequence_input, outputs=output) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) ``` #### 模型训练与评估 完成上述准备工作之后就可以开始训练过程,在此期间可以设置早停策略防止过拟合现象发生;同时保存最佳性能参数以便后续测试阶段调用。最后通过验证集上的表现衡量整个系统的有效性[^2]。 ```python history = model.fit(x_train, y_train, batch_size=BATCH_SIZE, epochs=EPOCHS, validation_split=0.1, callbacks=[ EarlyStopping(monitor='val_loss', patience=PATIENCE), ModelCheckpoint(filepath=model_path, save_best_only=True)] ) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值