使用 Elasticsearch 检测抄袭 (一)

2023-12-26 21:30

本文主要是介绍使用 Elasticsearch 检测抄袭 (一),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

作者:Priscilla Parodi

抄袭可以是直接的,涉及复制部分或全部内容,也可以是释义的,即通过更改一些单词或短语来重新表述作者的作品。

灵感和释义之间是有区别的。 即使你得出类似的结论,也可以阅读内容,获得灵感,然后用自己的话探索这个想法。

虽然抄袭长期以来一直是讨论的话题,但内容的加速制作和发布使其保持了相关性并构成了持续的挑战。

这一挑战不仅限于经常进行抄袭检查的书籍、学术研究或司法文件。 它还可以扩展到报纸甚至社交媒体。

随着信息的丰富和发布的便捷性,如何在可扩展的水平上有效地检查抄袭行为?

大学、政府实体和公司使用不同的工具,虽然简单的词汇搜索可以有效地检测直接抄袭,但主要的挑战在于识别释义内容。

如果你想一步一步地在你自己的电脑里实现如下的文章中所描述的练习,请详细阅读文章 “使用 Elasticsearch 检测抄袭 (二)”。

使用生成人工智能检测抄袭

生成人工智能出现了新的挑战。 人工智能生成的内容在复制时是否被视为抄袭?

例如,OpenAI 使用条款规定 OpenAI 不会对 API 为用户生成的内容主张版权。 在这种情况下,使用生成式人工智能的个人可以根据自己的喜好使用生成的内容,而无需引用。

然而,是否接受使用生成式人工智能来提高效率仍然是一个讨论的话题。

为了为抄袭检测做出贡献,OpenAI 开发了一个检测模型,但后来承认其准确性不够高。

“我们认为这对于独立检测来说不够高,需要与基于元数据的方法、人类判断和公共教育相结合才能更有效。”

挑战依然存在; 然而,随着更多工具的出现,现在检测抄袭的选项也增加了,即使是在释义和人工智能内容的情况下也是如此。

使用 Elasticsearch 检测抄袭

认识到这一点,在这篇博客中,我们正在探索自然语言处理 (NLP) 模型和向量搜索的另一个用例,即除元数据搜索之外的抄袭检测。

这通过 Python 示例进行了演示,其中我们利用包含 NLP 相关文章的 SentenceTransformers 的数据集。 我们通过执行 “语义文本相似性” 来检查摘要是否抄袭,考虑到使用之前导入 Elasticsearch 的文本嵌入模型生成的 “abstract” 嵌入。 此外,为了识别人工智能生成的内容 —— 人工智能抄袭,OpenAI 开发的 NLP 模型也被导入到 Elasticsearch 中。

下图说明了数据流:

在使用推理处理器的摄取管道期间,“abstract” 段落被映射到 768 维向量,即 “abstract_vector.predicted_value”。

映射:

"abstract_vector.predicted_value": { # Inference results field
"type": "dense_vector", 
"dims": 768, # model embedding_size
"index": "true", 
"similarity": "dot_product" # When indexing vectors for approximate kNN search, you need to specify the similarity function for comparing the vectors.

向量表示之间的相似性是使用向量相似性度量来测量的,该度量是使用 “similarity” 参数定义的。

余弦是默认的相似度度量,计算公式为 “(1 + cosine(query, vector)) / 2”。 除非需要保留原始向量并且无法提前对它们进行归一化,否则执行余弦相似度的最有效方法是将所有向量归一化为单位长度。 这有助于避免在搜索过程中执行额外的向量长度计算,而是使用 “dot_product”。

在同一管道中,另一个包含文本分类模型的推理处理器会检测内容是可能由人类编写的 “真实” 内容,还是可能由人工智能编写的 “假” 内容,并将 “openai- detector.predicted_value” 添加到每个文档中。

摄取管道:

client.ingest.put_pipeline( id="plagiarism-checker-pipeline",processors = [{"inference": { #for ml models - to infer against the data that is being ingested in the pipeline"model_id": "roberta-base-openai-detector", #text classification model id"target_field": "openai-detector", # Target field for the inference results"field_map": { #Maps the document field names to the known field names of the model."abstract": "text_field" # Field matching our configured trained model input. }}},{"inference": {"model_id": "sentence-transformers__all-mpnet-base-v2", #text embedding model id"target_field": "abstract_vector", # Target field for the inference results"field_map": {"abstract": "text_field" # Field matching our configured trained model input. Typically for NLP models, the field name is text_field.}}}]
)

在查询时,还采用相同的文本嵌入模型在 “query_vector_builder” 对象中生成查询 “model_text” 的向量表示。

k 最近邻 (kNN) 搜索找到与通过相似性度量测量的查询向量最接近的 k 个向量。

每个文档的 _score 是根据相似度得出的,确保较大的分数对应较高的排名。 这意味着该文档在语义上更加相似。 因此,我们打印三种可能性:如果分数> 0.9,我们正在考虑 “高度相似性”; 如果 < 0.7,“低相似度”,否则,“中等相似度”。 你可以根据你的用例灵活地设置不同的阈值,以确定什么级别的 _score 判定为抄袭。

此外,执行文本分类还可以检查文本查询中人工智能生成的元素。

询问:

from elasticsearch import Elasticsearch
from elasticsearch.client import MlClient#duplicated text - direct plagiarism testmodel_text = 'Understanding and reasoning about cooking recipes is a fruitful research direction towards enabling machines to interpret procedural text. In this work, we introduce RecipeQA, a dataset for multimodal comprehension of cooking recipes. It comprises of approximately 20K instructional recipes with multiple modalities such as titles, descriptions and aligned set of images. With over 36K automatically generated question-answer pairs, we design a set of comprehension and reasoning tasks that require joint understanding of images and text, capturing the temporal flow of events and making sense of procedural knowledge. Our preliminary results indicate that RecipeQA will serve as a challenging test bed and an ideal benchmark for evaluating machine comprehension systems. The data and leaderboard are available at http://hucvl.github.io/recipeqa.'response = client.search(index='plagiarism-checker', size=1,knn={"field": "abstract_vector.predicted_value","k": 9,"num_candidates": 974,"query_vector_builder": { #The 'all-mpnet-base-v2' model is also employed to generate the vector representation of the query in a 'query_vector_builder' object."text_embedding": {"model_id": "sentence-transformers__all-mpnet-base-v2","model_text": model_text}}}
)for hit in response['hits']['hits']:score = hit['_score']title = hit['_source']['title']abstract = hit['_source']['abstract']openai = hit['_source']['openai-detector']['predicted_value']url = hit['_source']['url']if score > 0.9:print(f"\nHigh similarity detected! This might be plagiarism.")print(f"\nMost similar document: '{title}'\n\nAbstract: {abstract}\n\nurl: {url}\n\nScore:{score}\n\n")if openai == 'Fake':print("This document may have been created by AI.\n")elif score < 0.7:print(f"\nLow similarity detected. This might not be plagiarism.")if openai == 'Fake':print("This document may have been created by AI.\n")else:print(f"\nModerate similarity detected.")print(f"\nMost similar document: '{title}'\n\nAbstract: {abstract}\n\nurl: {url}\n\nScore:{score}\n\n")if openai == 'Fake':print("This document may have been created by AI.\n")ml_client = MlClient(client)model_id = 'roberta-base-openai-detector' #open ai text classification modeldocument = [{"text_field": model_text}
]ml_response = ml_client.infer_trained_model(model_id=model_id, docs=document)predicted_value = ml_response['inference_results'][0]['predicted_value']if predicted_value == 'Fake':print("\nNote: The text query you entered may have been generated by AI.\n")

输出:

检测到高相似度! 这可能是抄袭。

High similarity detected! This might be plagiarism.Most similar document: 'RecipeQA: A Challenge Dataset for Multimodal Comprehension of Cooking Recipes'Abstract: Understanding and reasoning about cooking recipes is a fruitful research direction towards enabling machines to interpret procedural text. In this work, we introduce RecipeQA, a dataset for multimodal comprehension of cooking recipes. It comprises of approximately 20K instructional recipes with multiple modalities such as titles, descriptions and aligned set of images. With over 36K automatically generated question-answer pairs, we design a set of comprehension and reasoning tasks that require joint understanding of images and text, capturing the temporal flow of events and making sense of procedural knowledge. Our preliminary results indicate that RecipeQA will serve as a challenging test bed and an ideal benchmark for evaluating machine comprehension systems. The data and leaderboard are available at[ http://hucvl.github.io/recipeqa](http://hucvl.github.io/recipeqa).url:[http://aclweb.org/anthology/D18-1166](http://aclweb.org/anthology/D18-1166)Score:1.0

在此示例中,在利用数据集中的 “abstract” 值之一作为文本查询 “model_text” 后,识别出了抄袭。 相似度得分为1.0,表明相似度很高 —— 直接抄袭。 向量化查询和文档未被识别为人工智能生成的内容,这是预期的。

查询:

#similar text - paraphrase plagiarism test model_text = 'Comprehending and deducing information from culinary instructions represents a promising avenue for research aimed at empowering artificial intelligence to decipher step-by-step text. In this study, we present CuisineInquiry, a database for the multifaceted understanding of cooking guidelines. It encompasses a substantial number of informative recipes featuring various elements such as headings, explanations, and a matched assortment of visuals. Utilizing an extensive set of automatically crafted question-answer pairings, we formulate a series of tasks focusing on understanding and logic that necessitate a combined interpretation of visuals and written content. This involves capturing the sequential progression of events and extracting meaning from procedural expertise. Our initial findings suggest that CuisineInquiry is poised to function as a demanding experimental platform.'

输出:

High similarity detected! This might be plagiarism.Most similar document: 'RecipeQA: A Challenge Dataset for Multimodal Comprehension of Cooking Recipes'Abstract: Understanding and reasoning about cooking recipes is a fruitful research direction towards enabling machines to interpret procedural text. In this work, we introduce RecipeQA, a dataset for multimodal comprehension of cooking recipes. It comprises of approximately 20K instructional recipes with multiple modalities such as titles, descriptions and aligned set of images. With over 36K automatically generated question-answer pairs, we design a set of comprehension and reasoning tasks that require joint understanding of images and text, capturing the temporal flow of events and making sense of procedural knowledge. Our preliminary results indicate that RecipeQA will serve as a challenging test bed and an ideal benchmark for evaluating machine comprehension systems. The data and leaderboard are available at[ http://hucvl.github.io/recipeqa](http://hucvl.github.io/recipeqa).url:[http://aclweb.org/anthology/D18-1166](http://aclweb.org/anthology/D18-1166)Score:0.9302529Note: The text query you entered may have been generated by AI.

通过使用 AI 生成的文本更新文本查询 “model_text”,该文本传达相同的信息,同时最大限度地减少相似单词的重复,检测到的相似度仍然很高,但得分为 0.9302529,而不是 1.0 —— 释义抄袭 (paraphrase plagiarism) 。 人们还预计该由人工智能生成的查询会被检测到。

最后,考虑到文本查询 “model_text” 是关于 Elasticsearch 的文本,它不是这些文档之一的摘要,检测到的相似度为 0.68991005,根据考虑的阈值表明相似度较低。

查询:

#different text - not a plagiarismmodel_text = 'Elasticsearch provides near real-time search and analytics for all types of data.'

输出:

Low similarity detected. This might not be plagiarism.

尽管在人工智能生成的文本查询中以及在释义和直接复制内容的情况下可以准确地识别出抄袭行为,但在抄袭检测领域的导航涉及到承认各个方面。

在人工智能生成的内容检测的背景下,我们探索了一种做出有价值贡献的模型。 然而,认识到独立检测的固有局限性至关重要,因此需要结合其他方法来提高准确性。

文本嵌入模型的选择带来的可变性是另一个考虑因素。 使用不同数据集训练的不同模型会产生不同程度的相似性,凸显了生成的文本嵌入的重要性。

最后,在这些示例中,我们使用了文档的摘要。 然而,抄袭检测通常涉及大型文档,因此必须解决文本长度的挑战。 文本超出模型的标记限制是很常见的,需要在构建嵌入之前将其分割成块。 处理这个问题的一种实用方法是利用带有 dense_vector 的嵌套结构。

结论:

在这篇博客中,我们讨论了检测剽窃的挑战,特别是在释义和人工智能生成的内容中,以及如何将语义文本相似性和文本分类用于此目的。

通过结合这些方法,我们提供了抄袭检测的示例,其中我们成功识别了人工智能生成的内容、直接抄袭和转述抄袭。

主要目标是建立一个简化检测的过滤系统,但人工评估对于验证仍然至关重要。

如果你有兴趣了解有关语义文本相似性和 NLP 的更多信息,我们鼓励你也查看以下链接:

  • 什么是语义搜索?
  • 什么是自然语言处理(NLP)?
  • 使用 Elasticsearch 进行词汇和语义搜索
  • 通过摄取管道加上嵌套向量对大型文档进行分块等于轻松的段落搜索

原文:Elasticsearch:通过摄取管道加上嵌套向量对大型文档进行分块轻松地实现段落搜索-CSDN博客

这篇关于使用 Elasticsearch 检测抄袭 (一)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/540832

相关文章

C语言中联合体union的使用

本文编辑整理自: http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=179471 一、前言 “联合体”(union)与“结构体”(struct)有一些相似之处。但两者有本质上的不同。在结构体中,各成员有各自的内存空间, 一个结构变量的总长度是各成员长度之和。而在“联合”中,各成员共享一段内存空间, 一个联合变量

Tolua使用笔记(上)

目录   1.准备工作 2.运行例子 01.HelloWorld:在C#中,创建和销毁Lua虚拟机 和 简单调用。 02.ScriptsFromFile:在C#中,对一个lua文件的执行调用 03.CallLuaFunction:在C#中,对lua函数的操作 04.AccessingLuaVariables:在C#中,对lua变量的操作 05.LuaCoroutine:在Lua中,

Vim使用基础篇

本文内容大部分来自 vimtutor,自带的教程的总结。在终端输入vimtutor 即可进入教程。 先总结一下,然后再分别介绍正常模式,插入模式,和可视模式三种模式下的命令。 目录 看完以后的汇总 1.正常模式(Normal模式) 1.移动光标 2.删除 3.【:】输入符 4.撤销 5.替换 6.重复命令【. ; ,】 7.复制粘贴 8.缩进 2.插入模式 INSERT

Lipowerline5.0 雷达电力应用软件下载使用

1.配网数据处理分析 针对配网线路点云数据,优化了分类算法,支持杆塔、导线、交跨线、建筑物、地面点和其他线路的自动分类;一键生成危险点报告和交跨报告;还能生成点云数据采集航线和自主巡检航线。 获取软件安装包联系邮箱:2895356150@qq.com,资源源于网络,本介绍用于学习使用,如有侵权请您联系删除! 2.新增快速版,简洁易上手 支持快速版和专业版切换使用,快速版界面简洁,保留主

如何免费的去使用connectedpapers?

免费使用connectedpapers 1. 打开谷歌浏览器2. 按住ctrl+shift+N,进入无痕模式3. 不需要登录(也就是访客模式)4. 两次用完,关闭无痕模式(继续重复步骤 2 - 4) 1. 打开谷歌浏览器 2. 按住ctrl+shift+N,进入无痕模式 输入网址:https://www.connectedpapers.com/ 3. 不需要登录(也就是

Toolbar+DrawerLayout使用详情结合网络各大神

最近也想搞下toolbar+drawerlayout的使用。结合网络上各大神的杰作,我把大部分的内容效果都完成了遍。现在记录下各个功能效果的实现以及一些细节注意点。 这图弹出两个菜单内容都是仿QQ界面的选项。左边一个是drawerlayout的弹窗。右边是toolbar的popup弹窗。 开始实现步骤详情: 1.创建toolbar布局跟drawerlayout布局 <?xml vers

C#中,decimal类型使用

在Microsoft SQL Server中numeric类型,在C#中使用的时候,需要用decimal类型与其对应,不能使用int等类型。 SQL:numeric C#:decimal

探索Elastic Search:强大的开源搜索引擎,详解及使用

🎬 鸽芷咕:个人主页  🔥 个人专栏: 《C++干货基地》《粉丝福利》 ⛺️生活的理想,就是为了理想的生活! 引入 全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选,相信大家多多少少的都听说过它。它可以快速地储存、搜索和分析海量数据。就连维基百科、Stack Overflow、

flask 中使用 装饰器

因为要完成毕业设计,我用到fountain code做数据恢复。 于是在github上下载了fountain code的python原代码。 github上的作者用flask做了fountain code的demo。 flask是面向python的一个网站框架。 里面有用到装饰器。 今天笔试的时候,我也被问到了python的装饰器。

mathematica的使用

因为做实验用到Bloom filter这一技术,Bloom filter里面的数学公式可以用来画图。 那么用什么画图软件比较好呢? 当然是Mathematica啦。 利用代码Plot[{y=x},{x,0,100}] 就可以画出比较好的图 简直nice