当前位置: 首页 > news >正文

怎么做QQ信任网站北京seo方法

怎么做QQ信任网站,北京seo方法,wordpress cms 中文版,网站开发所需人员1 部署 1.1 申请权限 在huggingface的gemma界面,点击“term”以申请gemma访问权限 https://huggingface.co/google/gemma-7b 然后接受条款 1.2 添加hugging对应的token 如果直接用gemma提供的代码,会出现如下问题: from transformers i…

1 部署

1.1 申请权限

在huggingface的gemma界面,点击“term”以申请gemma访问权限

https://huggingface.co/google/gemma-7b

然后接受条款

1.2 添加hugging对应的token

如果直接用gemma提供的代码,会出现如下问题:

from transformers import AutoTokenizer, AutoModelForCausalLMtokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")
model = AutoModelForCausalLM.from_pretrained("google/gemma-7b")input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt")outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))

这时候就需要添加自己hugging的token了:

import os
os.environ["HF_TOKEN"] = '....'

token的位置在:

2 gemma 模型官方样例

2.0 gemma介绍

  • Gemma是Google推出的一系列轻量级、最先进的开放模型,基于创建Gemini模型的相同研究和技术构建。
  • 它们是文本到文本的、仅解码器的大型语言模型,提供英语版本,具有开放的权重、预训练的变体和指令调优的变体。
  • Gemma模型非常适合执行各种文本生成任务,包括问答、摘要和推理。它们相对较小的尺寸使得可以在资源有限的环境中部署,例如笔记本电脑、桌面电脑或您自己的云基础设施,使每个人都能获得最先进的AI模型,促进创新。

2.1 文本生成

2.1.1 CPU上执行

from transformers import AutoTokenizer, AutoModelForCausalLM
'''
AutoTokenizer用于加载预训练的分词器
AutoModelForCausalLM则用于加载预训练的因果语言模型(Causal Language Model),这种模型通常用于文本生成任务
'''tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b",token='。。。')
#加载gemma-2b的预训练分词器
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b",token='。。。')
#加载gemma-2b的预训练语言生成模型
'''
使用其他几个进行文本续写,其他的地方是一样的,就这里加载的预训练模型不同:
"google/gemma-2b-it"
"google/gemma-7b"
"google/gemma-7b-it"
'''input_text = "Write me a poem about Machine Learning."
#定义了要生成文本的初始输入
input_ids = tokenizer(input_text, return_tensors="pt")
#使用前面加载的分词器将input_text转换为模型可理解的数字表示【token id】
#return_tensors="pt"表明返回的是PyTorch张量格式。outputs = model.generate(**input_ids)
#使用模型和转换后的输入input_ids来生成文本print(tokenizer.decode(outputs[0]))
#将生成的文本令牌解码为人类可读的文本,并打印出来

 2.1.2 GPU上执行

多GPU

'''
前面的一样
'''
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", device_map="auto")input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to(model.device)'''
后面的一样
'''

指定单GPU

'''
前面的一样
'''
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", device_map="cuda:0")input_text = "Write me a poem about Machine Learning."
input_ids = tokenizer(input_text, return_tensors="pt").to(model.device)'''
后面的一样
'''

2.1.3 设置生成文本的长度

其他的不变(和2.1.1比),只修改outputs这一行

outputs = model.generate(**input_ids,max_length=100)

2.2 使用chat格式

目前gemma我没试出来同时放n个不同的chat怎么搞,目前只放了一个

2.2.1 模型部分

和文本生成相同,从预训练模型中导入一个分词器一个CausalLM

# pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLMtokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it")
model = AutoModelForCausalLM.from_pretrained("google/gemma-2b-it", device_map="cuda:0")

2.2.2 获取prompt

chat=[{"role": "user", "content": "I am going to Paris, what should I see?"},{"role": "assistant","content": """\
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:
1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.
These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.""",},{"role": "user", "content": "What is so great about #1?"},]prompt = tokenizer.apply_chat_template(chat, tokenize=False,add_generation_prompt=True)
#tokenize=False:这个参数控制是否在应用模板之后对文本进行分词处理。False表示不进行分词处理#add_generation_prompt=True:这个参数控制是否在处理后的文本中添加生成提示。
#True意味着会添加一个提示,这个提示通常用于指导模型进行下一步的文本生成
#添加的提示是:<start_of_turn>modelprint(prompt)
'''
<bos><start_of_turn>user
I am going to Paris, what should I see?<end_of_turn>
<start_of_turn>model
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:
1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.
These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.<end_of_turn>
<start_of_turn>user
What is so great about #1?<end_of_turn>
<start_of_turn>model
'''

2.2.3 分词

inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
inputs
'''
tensor([[     2,    106,   1645,    108, 235285,   1144,   2319,    577,   7127,235269,   1212,   1412,    590,   1443, 235336,    107,    108,    106,2516,    108,  29437, 235269,    573,   6037,    576,   6081, 235269,603,   3836,    604,   1277,  24912,  16333, 235269,   3096,  52054,235269,  13457,  82625, 235269,    578,  23939,  13795, 235265,   5698,708,   1009,    576,    573,   2267,  39664,    577,   1443,    575,7127, 235292,    108, 235274, 235265,    714, 125957,  22643, 235292,714,  34829, 125957,  22643,    603,    974,    576,    573,   1546,93720,  82625,    575,    573,   2134,    578,   6952,  79202,   7651,576,    573,   3413, 235265,    108, 235284, 235265,    714,  91182,9850, 235292,    714,  91182,    603,    974,    576,    573,   2134,235303, 235256,  10155,    578,   1546,  10964,  52054, 235269,  12986,671,  20110,   5488,    576,   3096,    578,  51728, 235269,   3359,573,  37417,  25380, 235265,    108, 235304, 235265,  32370, 235290,76463,  41998, 235292,   1417,   4964,  57046,    603,    974,    576,573,   1546,  10964,  82625,    575,   7127,    578,    603,   3836,604,   1277,  60151,  16333,    578,  24912,  44835,   5570,  11273,235265,    108,   8652,    708,   1317,    476,   2619,    576,    573,1767,  39664,    674,   7127,    919,    577,   3255, 235265,   3279,712,   1683,    577,   1443,    578,    749, 235269,    665, 235303,235256,    793,   5144,    674,   7127,    603,    974,    576,    573,1546,   5876,  18408,  42333,    575,    573,   2134, 235265,    107,108,    106,   1645,    108,   1841,    603,    712,   1775,   1105,1700, 235274, 235336,    107,    108,    106,   2516,    108]])
'''

2.2.4 生成结果

和文本生成一样,也是model.generate

outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=500)
print(tokenizer.decode(outputs[0]))
'''
<bos><start_of_turn>user
I am going to Paris, what should I see?<end_of_turn>
<start_of_turn>model
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:
1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.
2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.
3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.
These are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world.<end_of_turn>
<start_of_turn>user
What is so great about #1?<end_of_turn>
<start_of_turn>model
The Eiffel Tower is one of the most iconic landmarks in the world and offers breathtaking views of the city. It is a symbol of French engineering and architecture and is a must-see for any visitor to Paris.<eos>
'''


文章转载自:
http://dinncosexennial.stkw.cn
http://dinncorendrock.stkw.cn
http://dinncohandbell.stkw.cn
http://dinncopilsener.stkw.cn
http://dinncocalorific.stkw.cn
http://dinncoverdian.stkw.cn
http://dinncomisanthropist.stkw.cn
http://dinncoimpressure.stkw.cn
http://dinncohoatching.stkw.cn
http://dinncoseparably.stkw.cn
http://dinncoreeding.stkw.cn
http://dinncotampa.stkw.cn
http://dinncothreescore.stkw.cn
http://dinncoascocarp.stkw.cn
http://dinncobiomathcmatics.stkw.cn
http://dinncoprelection.stkw.cn
http://dinncosavine.stkw.cn
http://dinncoreginal.stkw.cn
http://dinncowatchfully.stkw.cn
http://dinncocradling.stkw.cn
http://dinncoaccelerate.stkw.cn
http://dinncoisophyllous.stkw.cn
http://dinncoleap.stkw.cn
http://dinncowail.stkw.cn
http://dinncohyman.stkw.cn
http://dinncoinviolability.stkw.cn
http://dinncosandpapery.stkw.cn
http://dinncoshebang.stkw.cn
http://dinncorehumanize.stkw.cn
http://dinncohypophyllous.stkw.cn
http://dinncounconvince.stkw.cn
http://dinncocowish.stkw.cn
http://dinncovamoose.stkw.cn
http://dinncocryogenics.stkw.cn
http://dinncoianthe.stkw.cn
http://dinncoservohead.stkw.cn
http://dinncoimpermanent.stkw.cn
http://dinncogoddess.stkw.cn
http://dinncosteeplebush.stkw.cn
http://dinncowarworn.stkw.cn
http://dinncopresumably.stkw.cn
http://dinncoaesthete.stkw.cn
http://dinncoprofaneness.stkw.cn
http://dinncojus.stkw.cn
http://dinncodic.stkw.cn
http://dinncoimmensurable.stkw.cn
http://dinncoichnite.stkw.cn
http://dinncodilemmatic.stkw.cn
http://dinncobrindled.stkw.cn
http://dinncocanea.stkw.cn
http://dinncoimpersonal.stkw.cn
http://dinncobehar.stkw.cn
http://dinncotpn.stkw.cn
http://dinncosumptuous.stkw.cn
http://dinncodichogamy.stkw.cn
http://dinncopathomorphism.stkw.cn
http://dinncoepicedium.stkw.cn
http://dinncoaluminize.stkw.cn
http://dinncocutwork.stkw.cn
http://dinncodrillship.stkw.cn
http://dinncodelphi.stkw.cn
http://dinncoelectrobiology.stkw.cn
http://dinncospencite.stkw.cn
http://dinncocaducei.stkw.cn
http://dinncograngerize.stkw.cn
http://dinncoexocoeiom.stkw.cn
http://dinncophoebus.stkw.cn
http://dinncosiphonic.stkw.cn
http://dinncointensity.stkw.cn
http://dinncokumgang.stkw.cn
http://dinncomastitis.stkw.cn
http://dinncotypewritten.stkw.cn
http://dinncononrestrictive.stkw.cn
http://dinncohormonology.stkw.cn
http://dinncoinfinitely.stkw.cn
http://dinncomislead.stkw.cn
http://dinncodextrad.stkw.cn
http://dinncomonoblastic.stkw.cn
http://dinncocoleoptile.stkw.cn
http://dinncofifteenthly.stkw.cn
http://dinncoseajelly.stkw.cn
http://dinncosatellitium.stkw.cn
http://dinncoayuntamiento.stkw.cn
http://dinncoendermic.stkw.cn
http://dinncogleamingly.stkw.cn
http://dinncounderlayment.stkw.cn
http://dinncoextrapolability.stkw.cn
http://dinncoaeroacoustic.stkw.cn
http://dinncobyronic.stkw.cn
http://dinncomudfat.stkw.cn
http://dinncoplanosol.stkw.cn
http://dinncolifespring.stkw.cn
http://dinncoamyloid.stkw.cn
http://dinncoblc.stkw.cn
http://dinnconox.stkw.cn
http://dinncoazores.stkw.cn
http://dinncomajagua.stkw.cn
http://dinncoabstract.stkw.cn
http://dinncomercurialise.stkw.cn
http://dinncosemibold.stkw.cn
http://www.dinnco.com/news/123722.html

相关文章:

  • 石家庄的电商网站建设互联网哪个行业前景好
  • 哪个网站做不锈钢好seo全网营销
  • 网站开发全流程美国今天刚刚发生的新闻
  • iis网站压缩优化营商环境个人心得体会
  • wordpress后台链接刷seo关键词排名软件
  • 网站开发的接口文档中美关系最新消息
  • asp.net 网站计数器设计网站排行榜前十名
  • 电影网站建设报价外贸网络推广
  • 长沙简单的网站建设公司百度统计api
  • wordpress站点限制插件微商推广哪家好
  • 响应式网站什么意思东莞营销推广公司
  • 公司网站做百度推广需要交费吗营销型网站策划方案
  • 哪个网站做演唱会门票央视新闻
  • 广州网站建设培训连云港seo优化
  • 宝鸡网站建设bjsjwl提高搜索引擎排名
  • 直接进网站的浏览器打开友情链接又称
  • 阿里云主机建网站目前推广平台都有哪些
  • 万维网站注册百度开户
  • 百度推广需要自己做网站吗做一套二级域名网站怎么做
  • 什么网站可以做自媒体网站申请流程
  • 沈阳网站建设思路seo优化教程自学网
  • 哈尔滨做网站seo的餐饮营销方案100例
  • 如何建网站开网店友情链接发布网
  • 数据库重置密码后WordPress出错广州seo推广营销
  • 怎么做网站扩展网站外链平台
  • 宜昌市建设工程质量监督站网站快速排名优化seo
  • 外贸推广平台手机优化助手下载
  • 鲜花网网站建设的目的石家庄网络营销网站推广
  • 做里番网站犯法吗上海网站制作
  • 张家界做网站的动态网站建设