我使用了TFBertModel和Tensorflow模型来结合和训练拥抱的面部变形。我想保存每个时代的val_accuracy的最佳模型。我使用'tensorflow检查点‘,但我得到了error.How我是否可以保存每个时代的最佳模型与transformers在tensorflow? from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.initializers import TruncatedNormal
from tensorflow.keras.losses import Cate
我正在使用Tensorflow为一个二进制情感分析类调整BERT。我想使用自定义训练循环/损失函数。然而,当我训练模型时,我得到了以下错误:ValueError: Internal error: Tried to take gradients (or similar) of a variable without handle data: Tensor("transformer_encoder/StatefulPartitionedCall:1019", shape=(), dtype=resource)。 为了进行调试,我尝试将我的训练循环简化为只计算标准的二进制交叉熵,这应
我的目标是进行五类文本分类 我正在使用cnnbase模型运行bert微调,但我的项目在loss.backward()停止,在cmd中没有任何提示。 我的程序可以在lstm和rcnn等rnn base上成功运行。 但是,当我运行某个cnnbase模型时,出现了一个奇怪的bug。 我的cnn模型代码: import torch
import torch.nn as nn
import torch.nn.functional as F
# from ..Models.Conv import Conv1d
from transformers.modeling_bert import BertPreT
我正在处理一个NLP问题(句子分类),并决定使用HuggingFace的TFBertModel以及Conv1D、平面和密集层。我正在使用functional并编译我的模型。但是,在model.fit()期间,在输出密集层会出现形状错误。
模式定义:
# Build model with a max length of 50 words in a sentence
max_len = 50
def build_model():
bert_encoder = TFBertModel.from_pretrained(model_name)
input_word_ids = tf.ke
我正在尝试保存一个调得很好的bert模型。我已经正确地运行了代码-它工作得很好,并且在ipython控制台中,我能够调用getPrediction并让它得到结果。 我保存了我的权重文件(最高为model.ckpt-33.data-00000-of-00001 我不知道我将如何保存模型以供重用。 我正在使用bert-tensorflow。 import json
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub
from datetime import datetime
from sklear
我正在尝试使用来自Keras集线器()的BERT多语言作为TensorFlow模型中的一个层。在不使用分发策略的情况下训练模型效果很好。但是,当尝试通过分发策略利用Google Cloud TPU时,训练模型失败,并出现以下错误:
ValueError: Variable (<tf.Variable 'bert/embeddings/word_embeddings:0' shape=(119547, 768) dtype=float32>) was not created in the distribution strategy scope of (<tens
我正在试验BERT嵌入文本分类。我正在使用这个代码来创建一个BERT嵌入层和一个用于二进制分类的密集层。
# Initialize session
sess = tf.Session()
class PaddingInputExample(object):
"""Fake example so the num input examples is a multiple of the batch size.
When running eval/predict on the TPU, we need to pad the number of examples
我正在运行一个相当定制的tensorflow模型,它来自以下回购系统:
# Initialize session
sess = tf.Session()
# # Load all files from a directory in a DataFrame.
# def load_directory_data(directory):
# data = {}
# data["sentence"] = []
# data["sentiment"] = []
# for file_path in os.listdir(direc
我想训练一个21级文本分类模型使用Bert。但是我的训练数据很少,所以下载了一个与5类类似的数据集,包含200万个样本。验证准确率达98%左右。现在,我想使用这个模型作为我的小定制数据的预训练模型。但是我得到了shape mismatch with tensor output_bias from checkpoint reader错误,因为检查点模型有5个类,而我的自定义数据有21个类。
NFO:tensorflow:Calling model_fn.
INFO:tensorflow:Running train on CPU
INFO:tensorflow:*** Features ***
我正在尝试使用tensorflow集线器上提供的预训练BERT来实现一个学习排名模型。我使用的是ListNet损失函数的一个变体,它要求每个训练实例都是与查询相关的几个排序文档的列表。我需要模型能够接受形状(batch_size,list_size,sentence_length)中的数据,其中模型在每个训练实例的'list_size‘轴上循环,返回排名并将它们传递给损失函数。在一个只包含密集层的简单模型中,通过增加输入层的维度很容易做到这一点。例如:
from tensorflow.keras.layers import Dense, Input
from tensorflow.ke
我试图在XLNet中做这样的事情,但是我在文档中找不到这个部分,任何帮助都是有价值的,谢谢!
# we access the transformer model within our bert object using the bert attribute
# (eg bert.bert instead of bert)
embeddings = bert.bert(input_ids, attention_mask=mask)[1] # access pooled activations with [1]
(而不是bert.bert,我试图用xlnet来实现它)