实体匹配模型包
项目描述
实体匹配模型
实体匹配模型(EMM)解决了在两个可能非常大的数据集之间匹配公司名称的问题。EMM可以使用分布式方法匹配数百万个名称。它使用字符串匹配中建立的候选选择技术,即:tfidf向量化和余弦相似度(进行了显著的优化),基于单词和字符的,以及排序的邻域索引。这些所谓的索引器在从现实世界的名称对候选者中选择时起到补充作用。在索引器之上,EMM有一个分类器,它具有基于字符串、基于排名和基于法人实体特征的优化功能,以估计公司名称匹配的置信度。
该分类器可以训练以给出字符串相似度得分或匹配概率。这两种类型的分数都很有用,尤其是在有很多看起来很好的匹配项可供选择时。可选地,EMM包还可以用于将属于一组共同公司的名称与地面真相中的共同公司名称进行匹配。例如,用于指代外部银行账户的所有不同名称。这一步骤将监督层的名称匹配得分汇总成一个匹配项。
该包设计为模块化,并且可以使用Pandas和Spark。使用前者训练的分类器可以与后者一起使用,反之亦然。
有关发布历史,请参阅 GitHub发布。
笔记本
有关代码的详细示例,请参阅 notebooks/
下的笔记本。
01-entity-matching-pandas-version.ipynb
:使用EMM的Pandas版本进行名称匹配。02-entity-matching-spark-version.ipynb
:使用EMM的Spark版本进行名称匹配。03-entity-matching-training-pandas-version.ipynb
:拟合监督模型并设置歧视阈值(Pandas)。04-entity-matching-aggregation-pandas-version.ipynb
:使用聚合层并设置歧视阈值(Pandas)。
文档
有关文档、设计和API,请参阅 文档。
查看一下
实体匹配模型库需要Python >= 3.7,并且对pip友好。要开始使用,只需执行以下操作
pip install emm
或者从我们的仓库中查看代码
git clone https://github.com/ing-bank/EntityMatchingModel.git
pip install -e EntityMatchingModel/
在这个例子中,代码以编辑模式(选项 -e)安装。
可以使用以下方式安装其他依赖项,例如
pip install "emm[spark,dev,test]"
现在您可以使用Python中的此包
import emm
恭喜,您现在可以使用实体匹配模型了!
快速运行
作为一个快速示例,您可以这样做
from emm import PandasEntityMatching
from emm.data.create_data import create_example_noised_names
# generate example ground-truth names and matching noised names, with typos and missing words.
ground_truth, noised_names = create_example_noised_names(random_seed=42)
train_names, test_names = noised_names[:5000], noised_names[5000:]
# two example name-pair candidate generators: character-based cosine similarity and sorted neighbouring indexing
indexers = [
{
'type': 'cosine_similarity',
'tokenizer': 'characters', # character-based cosine similarity. alternative: 'words'
'ngram': 2, # 2-character tokens only
'num_candidates': 5, # max 5 candidates per name-to-match
'cos_sim_lower_bound': 0.2, # lower bound on cosine similarity
},
{'type': 'sni', 'window_length': 3} # sorted neighbouring indexing window of size 3.
]
em_params = {
'name_only': True, # only consider name information for matching
'entity_id_col': 'Index', # important to set both index and name columns to pick up
'name_col': 'Name',
'indexers': indexers,
'supervised_on': False, # no supervided model (yet) to select best candidates
'with_legal_entity_forms_match': True, # add feature that indicates match of legal entity forms (e.g. ltd != co)
}
# 1. initialize the entity matcher
p = PandasEntityMatching(em_params)
# 2. fitting: prepare the indexers based on the ground truth names, eg. fit the tfidf matrix of the first indexer.
p.fit(ground_truth)
# 3. create and fit a supervised model for the PandasEntityMatching object, to pick the best match (this takes a while)
# input is "positive" names column 'Name' that are all supposed to match to the ground truth,
# and an id column 'Index' to check with candidate name-pairs are matching and which not.
# A fraction of these names may be turned into negative names (= no match to the ground truth).
# (internally, candidate name-pairs are automatically generated, these are the input to the classification)
p.fit_classifier(train_names, create_negative_sample_fraction=0.5)
# 4. scoring: generate pandas dataframe of all name-pair candidates.
# The classifier-based probability of match is provided in the column 'nm_score'.
# Note: can also call p.transform() without training the classifier first.
candidates_scored_pd = p.transform(test_names)
# 5. scoring: for each name-to-match, select the best ground-truth candidate.
best_candidates = candidates_scored_pd[candidates_scored_pd.best_match]
best_candidates.head()
对于Spark,您可以使用与Pandas版本相同的API的类SparkEntityMatching
。有关所有可用示例,请参阅notebooks/
下的教程笔记本。
项目贡献者
此包由ING Analytics批发银行编写。
联系和支持
通过Github问题联系WBAA团队。请注意,INGA-WB仅提供基于最佳努力的支援。
许可证
版权所有 ING WBAA 2023。实体匹配模型完全免费、开源,并许可在MIT许可证下。
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
emm-2.1.5.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5820db7a12f24145aeb71cc325cf90cb702baaec57adb7d924ca4cad6fbcd0e5 |
|
MD5 | dbc2a0fff0b97f17e57310e0d736b659 |
|
BLAKE2b-256 | 02ef3914f138bd8b6c38898cf9427c66c151d7de8b224ce503abcdb1f734d723 |
emm-2.1.5-py3-none-any.whl的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4fb70336fd9af3716acb6548f532c449f5c0545481914e6418a53b064ce3c2d0 |
|
MD5 | 1c07c584821f76d422324e2b543db60f |
|
BLAKE2b-256 | c4b5e61c5fa89565734cf59ed354dcfc89c5243081dddc1beb4c0b98c7fa4ba6 |