这些是我拥有的大型文件的前10行:(注意,这10行中只有一个用户,但我有成千上万的用户)
dput(testd)
structure(list(user = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), otime = structure(c(10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L
), .Label = c("2010-10-12T19:56:49Z", "2010-10-13T03:57:23Z",
"2010-10-13T16:41:35Z", "2010-10-13T20:05:43Z", "2010-10-13T23:31:51Z",
"2010-10-14T00:21:47Z", "2010-10-14T18:25:51Z", "2010-10-16T03:48:54Z",
"2010-10-16T06:02:04Z", "2010-10-17T01:48:53Z"), class = "factor"),
lat = c(39.747652, 39.891383, 39.891077, 39.750469, 39.752713,
39.752508, 39.7513, 39.758974, 39.827022, 39.749934),
long = c(-104.99251, -105.070814, -105.068532, -104.999073,
-104.996337, -104.996637, -105.000121, -105.010853,
-105.143191, -105.000017),
locid = structure(c(5L, 4L, 9L, 6L, 1L, 2L, 8L, 3L, 10L, 7L),
.Label …Run Code Online (Sandbox Code Playgroud) 我有一个数据集customerId,transactionDate,productId,purchaseQty加载到data.table中.对于每一行,我想计算前45天的总和,以及购买数量的平均值
productId customerID transactionDate purchaseQty
1: 870826 1186951 2016-03-28 162000
2: 870826 1244216 2016-03-31 5000
3: 870826 1244216 2016-04-08 6500
4: 870826 1308671 2016-03-28 221367
5: 870826 1308671 2016-03-29 83633
6: 870826 1308671 2016-11-29 60500
Run Code Online (Sandbox Code Playgroud)
我正在寻找这样的输出:
productId customerID transactionDate purchaseQty sumWindowPurchases
1: 870826 1186951 2016-03-28 162000 162000
2: 870826 1244216 2016-03-31 5000 5000
3: 870826 1244216 2016-04-08 6500 11500
4: 870826 1308671 2016-03-28 221367 221367
5: 870826 1308671 2016-03-29 83633 305000
6: 870826 1308671 2016-11-29 60500 60500
Run Code Online (Sandbox Code Playgroud)
因此,sumWindowPurchases包含当前交易日期45天窗口内客户/产品的purchaseQty总和.一旦我有了这个工作,抛出我需要的平均值和其他计算应该是微不足道的
我回到我的SQL根源并想到了一个自我加入:
select …Run Code Online (Sandbox Code Playgroud) 我试图使用函数获取每组数据帧的3个最常见数字,但忽略不太常见的值(每组),并允许唯一数字(如果存在).接受的答案将是最低的system.time
#my current function
library(plyr)
get.3modes.andcounts<- function(origtable,groupby,columnname) {
data <- ddply (origtable, groupby, .fun = function(xx){
c(m1 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[1])),
m2 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[2])),
m3 = paste(names(sort(table(xx[,columnname]),decreasing=TRUE)[3])),
counts=length2(xx[[columnname]], na.rm=TRUE) #http://www.cookbook-r.com/Manipulating_data/Summarizing_data/
) } )
return(data)
}
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# example df
col2<-c(4, 4, 4, 4, 5, 3, 3, 3, 2, 2, # group1 "5" is the less common
2, 2, 2, 4, 4, 3, 3, 2, 2, 2, # group2 "3" and …Run Code Online (Sandbox Code Playgroud) 我想在Ubuntu中安装pyrouge用于文本摘要评估。我使用this中的说明。
首先我写pip install pyrouge然后我必须写这个命令:pyrouge_set_rouge_path /absolute/path/to/ROUGE-1.5.5/directory.
在我的系统中,我写道:
pyrouge_set_rouge_path /home/afsharizadeh/anaconda3/lib/python3.6/site-packages/pyrouge
Run Code Online (Sandbox Code Playgroud)
得到这个:
例外:无法设置数据目录,因为路径 /home/afsharizadeh/anaconda3/lib/python3.6/site-packages/pyrouge/data 不存在。
并且
pyrouge_set_rouge_path /home/afsharizadeh/pyrouge-0.1.0/pyrouge
Run Code Online (Sandbox Code Playgroud)
得到这个:
例外:无法设置数据目录,因为路径 /home/afsharizadeh/pyrouge-0.1.0/pyrouge/data 不存在。
并且
pyrouge_set_rouge_path /home/afsharizadeh/pyrouge-0.1.0/pyrouge/test
Run Code Online (Sandbox Code Playgroud)
得到这个:
例外:在 /home/afsharizadeh/pyrouge-0.1.0/pyrouge/test/ROUGE-1.5.5.pl 中找不到 ROUGE 二进制文件。请通过运行pyrouge_set_rouge_path /path/to/rouge/home 设置正确的路径。
我知道关于这个问题的类似问题是在堆栈溢出中被问到的,但我无法解决我的问题,因为我根本不知道“ROUGE path”这个表达是什么意思。“通往 ROUGE-1.5.5 的路径”是什么意思?
我知道我有两个关于pyrouge的目录。其中一个是这个路径:~/anaconda3/lib/python3.6/site-packages/pyrouge另一个是我从站点下载的目录。这条路是:~/pyrouge-0.1.0。该目录还有其他三个目录,名称分别为:bin、pyrouge、pyrouge.egg-info。
基于此页面,我以这种格式编写:
set pyrouge_set_rouge_path=/home/afsharizadeh/anaconda3/lib/python3.6/site-packages/pyroug
Run Code Online (Sandbox Code Playgroud)
在这种格式之后,没有错误出现,但之后我输入:
python -m pyrouge.test
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
例外:无法设置数据目录,因为路径 /home/afsharizadeh/anaconda3/lib/python3.6/site-packages/pyroug/data 不存在。
-------------------------------------------------- -------------------- 在 0.592 秒内运行 11 个测试
失败(错误=9)
我该怎么办?
对于以下数据集,
Genre Amount
Comedy 10
Drama 30
Comedy 20
Action 20
Comedy 20
Drama 20
Run Code Online (Sandbox Code Playgroud)
我想构建一个ggplot2折线图,其中x轴是Genre,而y轴是所有量的总和(以条件为基础Genre).
我尝试过以下方法:
p = ggplot(test, aes(factor(Genre), Gross)) + geom_point()
p = ggplot(test, aes(factor(Genre), Gross)) + geom_line()
p = ggplot(test, aes(factor(Genre), sum(Gross))) + geom_line()
Run Code Online (Sandbox Code Playgroud)
但无济于事.
我目前正在构建一个系统,它将总结来自维基百科等网页的文章。
我能够从网页中提取文本,并且我知道 Open Text Summarizer API 可以帮助我进行摘要,但问题是我不知道如何正确使用它。
请问任何碰巧知道如何使用这个库的人?你能为我提供一个简单的例子吗?目前我正在用 C# 做我的项目。
我很难区分指示性摘要和信息性摘要。你能给我一个清楚的例子来说明它们之间的区别吗?
提前致谢!
我正在关注这个pytorch教程http://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html并尝试将此原则应用于摘要.其中编码序列大约为1000个字,而解码器目标为200个字.如何将seq2seq应用于此?我知道一次完成1000个单词的整个序列会非常昂贵且几乎不可行.因此将seq划分为20 seq并且并行运行可以得到答案.但我不知道如何实现它我也希望将注意力集中在它上面.
我使用 data.tree 结构来汇总文件文件夹中的各种信息。在每个文件夹中我都有许多文件(值),我需要为每个文件夹做的是总结该文件夹+所有子文件夹包含多少个文件。
\n\n示例数据:
\n\nlibrary(data.tree)\ndata <- data.frame(pathString = c("MainFolder",\n "MainFolder/Folder1",\n "MainFolder/Folder2",\n "MainFolder/Folder3",\n "MainFolder/Folder1/Subfolder1",\n "MainFolder/Folder1/Subfolder2"),\n Value = c(1,1,5,2,4,10))\ntree <- as.Node(data, Value)\nprint(tree, "Value")\n levelName Value\n1 MainFolder 1\n2 \xc2\xa6--Folder1 1\n3 \xc2\xa6 \xc2\xa6--Subfolder1 4\n4 \xc2\xa6 \xc2\xb0--Subfolder2 10\n5 \xc2\xa6--Folder2 5\n6 \xc2\xb0--Folder3 2\nRun Code Online (Sandbox Code Playgroud)\n\n我目前对问题的解决方案非常缓慢:
\n\n# Function to sum up file counts pr folder + subfolders\ntotal_count <- function(node) {\n results <- sum(as.data.frame(print(node, "Value"))$Value)\n return(results)\n}\n\n# Summing up file counts pr folder + subfolders\ntree$Do(function(node) node$Value_by_folder <- total_count(node))\n\n\n# Results\nprint(tree, "Value", "Value_by_folder")\n levelName Value Value_by_folder\n1 MainFolder 1 …Run Code Online (Sandbox Code Playgroud) 我正在 HuggingFace 上实现 BART,请参阅参考:https ://huggingface.co/transformers/model_doc/bart.html
以下是他们文档中用于创建生成摘要的代码:
from transformers import BartModel, BartTokenizer, BartForConditionalGeneration
model = BartForConditionalGeneration.from_pretrained('facebook/bart-large-cnn')
tokenizer = BartTokenizer.from_pretrained('facebook/bart-large')
def baseBart(ARTICLE_TO_SUMMARIZE):
inputs = tokenizer([ARTICLE_TO_SUMMARIZE], max_length=1024, return_tensors='pt')
# Generate Summary
summary_ids = model.generate(inputs['input_ids'], num_beams=4, max_length=25, early_stopping=True)
return [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids][0]
Run Code Online (Sandbox Code Playgroud)
我需要使我的摘要简洁,所以我设置max_length=25. 但这样做时,我得到的句子不完整,例如这两个例子:
EX1:左肺基底的混浊与之前的检查相比似乎稳定。左半身有抬高
EX 2:有正常的矿化和排列。未发现骨折或骨质病变。脚踝死了
如何确保预测的摘要是连贯的句子、完整的思想并且保持简洁。如果可能的话,我不想对汇总输出执行正则表达式,并在最后一个句点之后截断任何文本,但实际上让 BART 模型在最大长度内生成句子。
我尝试truncation=True在模型中进行设置,但没有成功。