我正在使用 PyTorch 创建实体提取模型bert-base-uncased,但是当我尝试运行该模型时,出现此错误:
Some weights of the model checkpoint at D:\Transformers\bert-entity-extraction\input\bert-base-uncased_L-12_H-768_A-12 were not used when initializing BertModel:
['cls.predictions.transform.dense.bias', 'cls.predictions.decoder.weight', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.bias', 'cls.seq_relationship.bias',
'cls.predictions.transform.LayerNorm.weight', 'cls.predictions.transform.dense.weight',
'cls.predictions.bias']
- This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to …Run Code Online (Sandbox Code Playgroud) python nlp pytorch bert-language-model huggingface-transformers
我已经为我的网络功能编写了 PyTorch 代码fit。但是当我tqdm在其中的循环中使用时,它不会从 0% 增加,这是我无法理解的原因。
这是代码:
from tqdm.notebook import tqdm
def fit(model, train_dataset, val_dataset, epochs=1, batch_size=32, warmup_prop=0, lr=5e-5):
device = torch.device('cuda:1')
model.to(device)
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False)
optimizer = AdamW(model.parameters(), lr=lr)
num_warmup_steps = int(warmup_prop * epochs * len(train_loader))
num_training_steps = epochs * len(train_loader)
scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps, num_training_steps)
loss_fct = nn.BCEWithLogitsLoss(reduction='mean').to(device)
for epoch in range(epochs):
model.train()
start_time = time.time()
optimizer.zero_grad()
avg_loss = 0
for step, (x, y_batch) in tqdm(enumerate(train_loader), total=len(train_loader)):
y_pred …Run Code Online (Sandbox Code Playgroud) 我编写了以下代码来在不同的子图中绘制 6 个饼图,但出现错误。如果我只使用它来绘制 2 个图表,则此代码可以正常工作,但除此之外还会产生错误。
我的数据集中有 6 个分类变量,它们的名称存储在 list 中cat_cols。图表将根据训练数据绘制train。
代码
fig, axes = plt.subplots(2, 3, figsize=(24, 10))
for i, c in enumerate(cat_cols):
train[c].value_counts()[::-1].plot(kind = 'pie', ax=axes[i], title=c, autopct='%.0f', fontsize=18)
axes[i].set_ylabel('')
plt.tight_layout()
Run Code Online (Sandbox Code Playgroud)
错误
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'
Run Code Online (Sandbox Code Playgroud)
我们如何纠正这个问题?
我有一个大小为 4 GB 的 XML 文件。我想解析它并将其转换为数据框以对其进行处理。但由于文件太大,以下代码无法将文件转换为 Pandas 数据帧。该代码只是不断加载并且不提供任何输出。但是当我将它用于较小尺寸的类似文件时,我获得了正确的输出。
任何人都可以建议任何解决方案吗?也许是加速从 XML 到数据帧的转换过程或将 XML 文件分割成更小的子集的代码。
有什么建议我是否应该在我的个人系统(2 GB RAM)上处理如此大的 XML 文件,或者我应该使用 Google Colab。如果使用 Google Colab,那么有没有什么方法可以更快地将如此大的文件上传到驱动器,从而上传到 Colab?
以下是我使用过的代码:
import xml.etree.ElementTree as ET
tree = ET.parse("Badges.xml")
root = tree.getroot()
#Column names for DataFrame
columns = ['row Id',"UserId",'Name','Date','Class','TagBased']
#Creating DataFrame
df = pd.DataFrame(columns = columns)
#Converting XML Tree to a Pandas DataFrame
for node in root:
row_Id = node.attrib.get("Id")
UserId = node.attrib.get("UserId")
Name = node.attrib.get("Name")
Date = node.attrib.get("Date")
Class = node.attrib.get("Class")
TagBased = node.attrib.get("TagBased")
df = …Run Code Online (Sandbox Code Playgroud) 我有以下数据框,其中包含不同间隔的不同作业开始和结束时间的数据。数据框的一小部分如下所示。
数据框(df):
result | job | time
START | JOB0 | 1357
START | JOB2 | 2405
END | JOB2 | 2379
START | JOB3 | 4010
END | JOB0 | 5209
END | JOB3 | 6578
START | JOB0 | 6000
END | JOB0 | 6100
Run Code Online (Sandbox Code Playgroud)
(注意 - 原始数据帧有 5 个作业(JOB0 到 JOB4)我想将列的值(START和END)转换result为数据帧中的单个列。
所需数据框(df2)
job | START | END
JOB0 | 1357 | 5209
JOB2 | 2405 | 2379
JOB3 | 4010 | …Run Code Online (Sandbox Code Playgroud) 我正在 VS Code 中工作,在已安装的名为where 的 conda环境中运行 Python 脚本。但是,当我导入它并运行脚本时,出现以下错误:myenvsklearn
Traceback (most recent call last):
File "d:\ML\Project\src\train.py", line 5, in <module>
from sklearn.linear_models import LinearRegression
ModuleNotFoundError: No module named 'sklearn'
Run Code Online (Sandbox Code Playgroud)
我已尝试了以下建议的所有可能的解决方案,但没有任何效果对我有用:
有人可以建议一种不同的方法来解决这个问题吗?
python ×5
dataframe ×2
pandas ×2
python-3.x ×2
matplotlib ×1
nlp ×1
numpy ×1
pip ×1
pivot-table ×1
pytorch ×1
scikit-learn ×1
tqdm ×1
xml ×1
xml-parsing ×1