全都会!预测蛋白质标注!创建讲义!解释数学公式!最懂科学的智能NLP模型Galactica尝鲜 ⛵

作者:韩信子@ShowMeAI
机器学习实战系列:https://www.showmeai.tech/tutorials/41
深度学习实战系列:https://www.showmeai.tech/tutorials/42
自然语言处理实战系列:https://www.showmeai.tech/tutorials/45
本文地址:https://www.showmeai.tech/article-detail/405
声明:版权所有,转载请联系平台与作者并注明出处
收藏ShowMeAI查看更多精彩内容
引言


Galactica 是 Meta AI 开源的大型语言模型,基于 Transformer 架构构建,主要使用科学文章和研究论文作为数据,并使用 GROBID 库将文档从 pdf 转换为文本作为语料进行学习。


Galactica 模型使用单个模型管理多个科学任务。可以完成推理、创建讲义、预测资料引用等,有以下特点:
- 模型包括125M-120B参数之间的5种不同尺寸。
- 该模型使用 2048 长度的上下文窗口。
- 用于管理特定数据类型的“专业”标记化方法。

Galactica 模型在面向科学的数据集上做到了最先进的性能。与升级后的 GPT-3 或 OPT 相比,它在 TruthfulQA 数据集中问题结果更少,可作为开源项目使用,在本篇内容中,ShowMeAI就带大家一起体验一下这个科学界的巨型语言模型。
实践
安装与加载
我们可以通过如下命令安装Galactica模型:
pip install git+https://github.com/paperswithcode/galai
注意:Galactica 模型适用于 Python 版本 3.8 和 3.9。目前Python 3.10 及更高版本时模型安装失败。主要是由于 promptsource-library 依赖要求。
使用下述命令导入模型:
import galai as gal
通过load_model函数加载模型。
model = gal.load_model("base", num_gpus = 1)
加载模型时可以指定加载的预训练模型版本,我们在这里使用“base”版本,模型包括 1.3B(13亿)参数。可选的版本包括“mini”,“base”,“standard”,“large” 和 “huge”,参数量从 125m 到 120b。
更大的模型需要更多内存与计算资源,我们在这里基于内存情况选择“base”版本,它消耗大约 11GB 的内存。
load_model的第2个参数是可选的,它指定GPU的数量。
模型使用示例
下面我们开始使用和体验模型,下面是一个百科解释类的示例:
model.generate("We can explain Brain as", new_doc=True, top_p=0.7, max_length=200)
模型包括其他参数,我们可以在参数设置中限制输出文本长度,这些参数类似于 GPT-3 模型。
模型输出的结果如下:
We can explain Brain as a computer program that takes in data from the external world, and produces an output as a result. The Brain is the machine that makes decisions about what to do. The Brain is the part of the brain that is made up of neurons, the basic building blocks of the brain. Neurons are the smallest units of the brain. Each neuron contains a membrane and a set of synapses that allow it to communicate with other neurons.\n\n[IMAGE]\n\nFigure Caption: Figure 10.2.110.2.1: Neurons are the smallest units of the brain.\n\n# What are the Functions of Neurons?\n\nNeurons are the basic building blocks of the brain. The brain is the part of the body that is made up of neurons. Neurons communicate with each other using chemical signals called neurotransmitters. The brain has many different types of neurons. The different types of neurons in the brain are called neurons of the different types. Neurons of different types'
HuggingFace+Galactica
Galactica 模型也可以使用 HuggingFace 加载和使用,我们来看看这个过程,首先我们导入工具库:
!pip install accelerate #to run with the gpu
from transformers import AutoTokenizer, OPTForCausalLM
注意:使用 GPU 运行模型时需要accelerate库。当仅使用 CPU 运行模型时,我们可以跳过安装“accelerate”库。当仅使用 CPU 运行时,该模型很慢。因此,如果大家有 GPU 资源,我们尽量使用GPU运行它。
我们接下来选择模型版本,不同大小的模型分别为“125m”、“1.3b”、“6.7b”、“30b”和“120b”。我们现在将使用以下代码运行 1.25 亿个参数的最小版本:
tokenizer = AutoTokenizer.from_pretrained("facebook/galactica-125m")
model = OPTForCausalLM.from_pretrained("facebook/galactica-125m", device_map="auto")
如果要使用其他版本,大家只需将125m换成其他的版本(“1.3b”、“6.7b”、“30b”和“120b”)即可。
加载完模型之后我们来测试一下,这次我们来测试一下模型的推理推断能力。我们以文本形式提供输入:
input_text = "Car 1 speed is 30km/h and Car 2 speed is 50km/h. Which car travels faster and how much? <work>"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda") #when running with gpu is required to add the ".to("cuda")"
我们使用最小版本的Galactica 模型,就准确返回此推理任务的正确答案,如下所示:
Car 1 travels faster than Car 2 (30km/h vs. 50km/h). calc_1.py
result = 30/50 with open(“output.txt”, “w”) as file: file.write(str(round(result)))<<run: “calc_1.py”>> <<read: “output.txt”>> 10 So 10 km. Car 1 travels faster than Car 2 (50km/h vs. 30km/h). calc_2.py ```result = 50/30 … Answer: 20
参考资料
- Galactica 官方网站:https://www.galactica.org/
- GROBID 官方网站:https://grobid.readthedocs.io/en/latest/Introduction/
- Galactica: A Large Language Model for Science:https://galactica.org/static/paper.pdf
推荐阅读
- 数据分析实战系列 :https://www.showmeai.tech/tutorials/40
- 机器学习数据分析实战系列:https://www.showmeai.tech/tutorials/41
- 深度学习数据分析实战系列:https://www.showmeai.tech/tutorials/42
- TensorFlow数据分析实战系列:https://www.showmeai.tech/tutorials/43
- PyTorch数据分析实战系列:https://www.showmeai.tech/tutorials/44
- NLP实战数据分析实战系列:https://www.showmeai.tech/tutorials/45
- CV实战数据分析实战系列:https://www.showmeai.tech/tutorials/46
- AI 面试题库系列:https://www.showmeai.tech/tutorials/48
全都会!预测蛋白质标注!创建讲义!解释数学公式!最懂科学的智能NLP模型Galactica尝鲜 ⛵的更多相关文章
- mySql创建带解释的表及给表和字段加注释的实现代码
1.创建带解释的表 CREATE TABLE test_table( t_id INT(11) PRIMARY KEY AUTO_INCREMENT COMMENT '设置主键自增', t_name ...
- pycharm创建Flask项目,jinja自动补全,flask智能提示
pycharm创建Flask项目,jinja自动补全,flask智能提示 之前一直都是用在idea里创建空项目然后导入,之后就没有各种的智能提示,在选择文类,选择模板之类的地方就会很麻烦. 步骤1:用 ...
- Eclipse创建Android模拟器创建选项解释
- word2vec 中的数学原理具体解释(五)基于 Negative Sampling 的模型
word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注. 因为 word2vec 的作者 Tomas ...
- word2vec 中的数学原理具体解释(四)基于 Hierarchical Softmax 的模型
word2vec 是 Google 于 2013 年开源推出的一个用于获取 word vector 的工具包,它简单.高效,因此引起了非常多人的关注.因为 word2vec 的作者 Tomas M ...
- 网络流量预测 国内外研究现状【见评论】——传统的ARIMA、HMM模型,目前LSTM、GRU、CNN应用较多,貌似小波平滑预处理步骤非常关键
Time Series Anomaly Detection in Network Traffic: A Use Case for Deep Neural Networks from:https://j ...
- iOS 资源大全
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
- IOS中文版资源库
Swift 语言写成的项目会被标记为 ★ ,AppleWatch 的项目则会被标记为 ▲. [转自]https://github.com/jobbole/awesome-ios-cn#librari ...
- 墙裂推荐 iOS 资源大全
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
- iOS 资源大全整理
这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...
随机推荐
- Solutions:网站搜索 - Elastic Site Search
- CentOS 7.7系统安装Redis 6.0.3
前提操作 避免出现如下的错误 yum -y install gcc tcl yum -y install centos-release-scl yum -y install devtoolset-9- ...
- Beats:使用 Filebeat 导入 JSON 格式的日志文件
转载自:https://blog.csdn.net/UbuntuTouch/article/details/108504014 在今天的文章中,我来用另外的一种方式来展示如何导入一个 JSON 格式的 ...
- 1_Maven
一. 引言 1.1 项目管理问题 项目中jar包资源越来越多, jar包的管理越来越沉重 1.1.1 繁琐 要为每个项目手动导入所需的jar, 需要搜集全部的jar 1.1.2 复杂 项目中的jar如 ...
- 2020-2021 Winter Petrozavodsk Camp, Belarusian SU Contest (XXI Open Cup, Grand Prix of Belarus) 题解
题目列表 C. Brave Seekers of Unicorns D. Bank Security Unification G. Biological Software Utilities I. B ...
- Codeforces Round #822 (Div. 2) A-F
比赛链接 A 题解 知识点:贪心. 注意到任意三根木棍的相等最优解是最长减最小,因此从小到大排序,三个三个取,取最小值. 时间复杂度 \(O(n\log n)\) 空间复杂度 \(O(n)\) 代码 ...
- set 学习笔记
一.声明 1.头文件 \(include<set>//包括set和multiset两个容器\) 2.声明 \(set<int> s\) s自带一个维度 二.迭代器 对" ...
- 齐博x1如何开启自定义标签模板功能
为安全起见,同时也为了避免用户随意添加风格导致默认模板不协调,系统默认关闭了类似V系列的自定义修改模板功能.如下图所示,默认是关闭的 你如果需要启用的话,把下面的代码,参考下图导进去后,就可以增加一个 ...
- 在不受支持的 Mac 上安装 macOS Ventura、Monterey、Big Sur (OpenCore Legacy Patcher)
请访问原文链接:https://sysin.org/blog/install-macos-13-on-unsupported-mac/,查看最新版.原创作品,转载请保留出处. 作者主页:www.sys ...
- $_SERVER["REQUEST_URI"],在 PHP 众多预定义服务器变量中,$_SERVER["REQUEST_URI"] 算是经常用到的,但是这个变量只有 apache 才支持
例如访问:http://localhost/index.php?app=lunbo获取到的$_SERVER["REQUEST_URI"]为"/index.php?app= ...