资源简介
knowledge_representation_pytorch.zip
代码片段和文件信息
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2017-12-15 15:31:32
# @Author : jimmy (jimmywangheng@qq.com)
# @link : http://sdcs.sysu.edu.cn
# @Version : $Id$
import os
import random
from copy import deepcopy
from utils import Triple
# Change the head of a triple randomly
# without checking whether it is a false negative sample.
def corrupt_head_raw(triple entityTotal):
newTriple = deepcopy(triple)
oldHead = triple.h
while True:
newHead = random.randrange(entityTotal)
if newHead != oldHead:
break
newTriple.h = newHead
return newTriple
# Change the tail of a triple randomly
# without checking whether it is a false negative sample.
def corrupt_tail_raw(triple entityTotal):
newTriple = deepcopy(triple)
oldTail = triple.t
while True:
newTail = random.randrange(entityTotal)
if newTail != oldTail:
break
newTriple.t = newTail
return newTriple
# Change the head of a triple randomly
# with checking whether it is a false negative sample.
# If it is regenerate.
def corrupt_head_filter(triple entityTotal tripleDict):
newTriple = deepcopy(triple)
while True:
newHead = random.randrange(entityTotal)
if (newHead newTriple.t newTriple.r) not in tripleDict:
break
newTriple.h = newHead
return newTriple
# Change the tail of a triple randomly
# with checking whether it is a false negative sample.
# If it is regenerate.
def corrupt_tail_filter(triple entityTotal tripleDict):
newTriple = deepcopy(triple)
while True:
newTail = random.randrange(entityTotal)
if (newTriple.h newTail newTriple.r) not in tripleDict:
break
newTriple.t = newTail
return newTriple
# Split the tripleList into #num_batches batches
def getBatchList(tripleList num_batches):
batchSize = len(tripleList) // num_batches
batchList = [0] * num_batches
for i in range(num_batches - 1):
batchList[i] = tripleList[i * batchSize : (i + 1) * batchSize]
batchList[num_batches - 1] = tripleList[(num_batches - 1) * batchSize : ]
return batchList
def getThreeElements(tripleList):
headList = [triple.h for triple in tripleList]
tailList = [triple.t for triple in tripleList]
relList = [triple.r for triple in tripleList]
return headList tailList relList
# Sample a batch of #batchSize triples from tripleList
def getBatch_clean_random(tripleList batchSize):
newTripleList = random.sample(tripleList batchSize)
ph pt pr = getThreeElements(newTripleList)
return ph pt pr
def getBatch_clean_all(tripleList):
ph pt pr = getThreeElements(tripleList)
return ph pt pr
# Corrupt the head or tail according to Bernoulli Distribution
# (See “Knowledge Graph embedding by Translating on Hyperplanes“ paper)
# without checking whether it is a false negative sample.
def corrupt_raw_two_v2(triple entityTotal tail_per_head head_per_tail):
rel = triple.r
split = tail_per_head[rel] / (tail_per_head[rel] + head_per_tail[rel])
random_number = random.random()
if random_number < split:
newTriple = corrupt_head_raw(triple en
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-04 11:16 knowledge_representation_pytorch\
文件 1066 2019-01-04 11:16 knowledge_representation_pytorch\LICENSE.md
文件 14941 2019-01-04 11:16 knowledge_representation_pytorch\transE_pytorch.py
文件 8196 2019-01-04 11:16 knowledge_representation_pytorch\.DS_Store
文件 16018 2019-01-04 11:16 knowledge_representation_pytorch\transH_Bernoulli_pytorch.py
文件 15714 2019-01-04 11:16 knowledge_representation_pytorch\transH_pytorch.py
文件 17041 2019-01-04 11:16 knowledge_representation_pytorch\transR_Bernoulli_pytorch.py
文件 28987 2019-01-04 11:16 knowledge_representation_pytorch\evaluation.py
目录 0 2019-01-04 11:16 knowledge_representation_pytorch\datasets\
文件 14340 2019-01-04 11:16 knowledge_representation_pytorch\datasets\.DS_Store
目录 0 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\
文件 307288 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\negtest2id.txt
文件 277711 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\test2id.txt
文件 6148 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\.DS_Store
文件 4176719 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\triple2id.txt
文件 76466 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\negvalid2id.txt
文件 171 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\relation2id.txt
文件 2 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\one_to_one_test.txt
文件 69185 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\valid2id.txt
文件 1730406 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\entity2id.txt
文件 2 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\one_to_many_test.txt
文件 3829834 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\train2id.txt
文件 2 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\many_to_many_test.txt
文件 277711 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\many_to_one_test.txt
文件 250 2019-01-04 11:16 knowledge_representation_pytorch\datasets\FB13\head_tail_proportion.pkl
目录 0 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\
文件 68910 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\test2id.txt
文件 6148 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\.DS_Store
文件 2093214 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\triple2id.txt
文件 363 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\relation2id.txt
文件 605 2019-01-04 11:16 knowledge_representation_pytorch\datasets\WN18\one_to_one_test.txt
............此处省略91个文件信息
相关资源
- 30天自制操作系统_光盘.rar
- Algorithm-Design-Solution.zip
- Redis开发与运维高清带书签(付磊)
- OperatingSystemConcepts.pdf
- 开关电源SPICE仿真与实用设计.zip
- 《DeepLearning》深度学习圣经-IanGoodfe
- 水印.rar
- OperatingSystemConcepts9thEdition.pdf
- my-start-spring-io.rar
- 密码编码学与网络安全原理与实践第
- 利用QQ聊天抓对方IP大概地理位置.ra
- RVDS4.1破解补丁.rar
- 信合流水软件(流水打印软件)v8.0免
- 全国1KM精度的人口数量数据2005年、
- 北京poi.rar
- PROTEUS.zip
- PatternRecognitionAndMachineLearning.zip
- 简明微波-西电梁昌洪-完整版.zip
- 测量工具CASS191108.rar
- KRTCLUB2.1.2.69.rar
- GBT软件测试标准--国家标准.rar
- 从610F到610G-2018.5.pptx
- F3飞控.zip
- 32串口实验.zip
- DiscreteMathematicsandItsApplications7th及答案
- CMOSCircuitDesignLayoutandSimulation3rdEdition
- 视觉slam14讲PPT.zip
- EXE病毒样本.rar
-
River_Line_la
yer1820_polyline.shp - cdll反编译工具包.rar
评论
共有 条评论