Edges
This class is used to get the edges of the word graph.
Methods:
Name | Description |
---|---|
__init__ |
Dict[int, str], node_features: np.ndarray, node_embeddings: np.ndarray) The constructor of the Edges class. |
get_similarity |
int, emb2: int) -> float This method is used to get the similarity between two nodes. |
get_pmi |
List[str], word1: str, word2: str) -> float This method is used to get the PMI between two nodes. |
get_edge_features |
List[str]) This method is used to get the edge features of the word graph. |
Source code in semantics/graphs/temporal_graph.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
__init__(index_to_key, node_features, node_embeddings)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index_to_key |
Dict[int, str]
|
the index of the nodes of the word graph. The keys are the indices of the nodes and the values are the words of the nodes. |
required |
node_features |
ndarray
|
the features of the nodes of the word graph of shape (num_nodes, 3) where num_nodes is the number of nodes in the graph. |
required |
node_embeddings |
ndarray
|
the embeddings of the nodes of the word graph from the MLM model, of shape (num_nodes, 768). |
required |
Source code in semantics/graphs/temporal_graph.py
get_edge_features(dataset, sim_threshold=0.5)
This method is used to get the edge features of the word graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
List[str]
|
the dataset to get the edge features from |
required |
sim_threshold |
float
|
the similarity threshold to create an edge between two nodes. Default: 0.5. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
edge_index |
ndarray
|
the edge index of the word graph of shape (2, num_edges) where num_edges is the number of edges in the graph. The first row contains the indices of the first node of the edge and the second row contains the indices of the second node of the edge. An edge is created if the similarity between the two nodes is greater than sim_threshold. |
edge_features |
ndarray
|
the edge features of the word graph of shape (num_edges, 3) where num_edges is the number of edges in the graph. The features are:
|
Source code in semantics/graphs/temporal_graph.py
get_pmi(data, word1, word2)
This method is used to get the PMI between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
word1 |
str
|
the first node (word) |
required |
word2 |
str
|
the second node (word) |
required |
Returns:
Name | Type | Description |
---|---|---|
pmi |
float
|
the PMI between the two words in the dataset |
Source code in semantics/graphs/temporal_graph.py
get_similarity(emb1, emb2)
This method is used to get the similarity between two nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
emb1 |
int
|
the first index of the embedding in node_embeddings |
required |
emb2 |
int
|
the second index of the embedding in node_embeddings |
required |
Returns:
Name | Type | Description |
---|---|---|
similarity |
float
|
the similarity between the two embeddings |