Giter Club home page Giter Club logo

albert_link_prediction's Introduction

albert-fc for LP(Link Prediction),链接预测

概述

链接预测是一种根据KG中已存在的实体去预测缺失事实的任务,是一种有前途的、广泛研究的、旨在解决KG的不完整的任务。

方法

利用huggingface/transformers中的albert+fc进行知识图谱链接预测。

利用albert加载中文预训练模型,后接前馈网络。利用albert预训练模型进行fine-tune。

整个流程是:

  • 数据经albert后获取最后的隐层hidden_state=768
  • 根据albert的last hidden_state,获取[CLS]的hidden_state经一层前馈网络进行分类

image

数据说明

数据形式见data/

训练数据示例如下,其中各列为头实体关系尾实体

科学,包涵,自然、社会、思维等领域
科学,外文名,science
科学,拼音,kē xué
科学,中文名,科学
科学,解释,发现、积累的真理的运用与实践

训练和预测见(examples/test_lp.py)

    lp = LP(args)
    if train_bool(args.train):
        lp.train()
    else:
        lp.load()
        entities = get_entity('../data/entities.txt')
        predict_result = lp.predict_tail('科学', '包涵', entities)
        predict_result = sorted(predict_result.items(), key=lambda x: x[1], reverse=True)
        print(predict_result[:10])

        predict_result = lp.predict_tail('编译器', '外文名', entities)
        predict_result = sorted(predict_result.items(), key=lambda x: x[1], reverse=True)
        print(predict_result[:10])

项目结构

  • data
    • test.sample.csv
    • train.sample.csv
  • examples
    • test_lp.py #训练及预测
  • model
    • pretrained_model #存放预训练模型和相关配置文件
      • config.json
      • pytorch_model.bin
      • vocab.txt
  • link_prediction
    • dataset.py
    • model.py
    • module.py
  • utils
    • log.py

参考

albert_link_prediction's People

Contributors

jiangnanboy avatar

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.