darabos commited on
Commit
e22b028
·
1 Parent(s): 5426f27

Make this suitable for demo deployment.

Browse files
examples/Using a model CHANGED
@@ -295,7 +295,7 @@
295
  }
296
  }
297
  },
298
- "name": "Create graph",
299
  "outputs": {
300
  "output": {
301
  "name": "output",
@@ -320,7 +320,7 @@
320
  "relations": null
321
  },
322
  "status": "planned",
323
- "title": "Create graph"
324
  },
325
  "dragHandle": ".bg-primary",
326
  "height": 322.0,
 
295
  }
296
  }
297
  },
298
+ "name": "Organize",
299
  "outputs": {
300
  "output": {
301
  "name": "output",
 
320
  "relations": null
321
  },
322
  "status": "planned",
323
+ "title": "Organize"
324
  },
325
  "dragHandle": ".bg-primary",
326
  "height": 322.0,
lynxkite-graph-analytics/src/lynxkite_graph_analytics/lynxkite_ops.py CHANGED
@@ -165,11 +165,11 @@ def cypher(bundle: core.Bundle, *, query: ops.LongStr, save_as: str = "result"):
165
  return bundle
166
 
167
 
168
- @op("Organize bundle")
169
- def organize_bundle(bundle: core.Bundle, *, code: ops.LongStr):
170
  """Lets you rename/copy/delete DataFrames, and modify relations.
171
 
172
- TODO: Use a declarative solution instead of Python code. Add UI.
173
  """
174
  bundle = bundle.copy()
175
  exec(code, globals(), {"bundle": bundle})
@@ -320,7 +320,7 @@ def view_tables(bundle: core.Bundle, *, limit: int = 100):
320
  view="graph_creation_view",
321
  outputs=["output"],
322
  )
323
- def create_graph(bundle: list[core.Bundle], *, relations: str = None) -> core.Bundle:
324
  """Replace relations of the given bundle
325
 
326
  relations is a stringified JSON, instead of a dict, because complex Yjs types (arrays, maps)
 
165
  return bundle
166
 
167
 
168
+ @op("Organize")
169
+ def organize(bundle: list[core.Bundle], *, code: ops.LongStr) -> core.Bundle:
170
  """Lets you rename/copy/delete DataFrames, and modify relations.
171
 
172
+ TODO: Merge this with "Create graph".
173
  """
174
  bundle = bundle.copy()
175
  exec(code, globals(), {"bundle": bundle})
 
320
  view="graph_creation_view",
321
  outputs=["output"],
322
  )
323
+ def create_graph(bundle: core.Bundle, *, relations: str = None) -> core.Bundle:
324
  """Replace relations of the given bundle
325
 
326
  relations is a stringified JSON, instead of a dict, because complex Yjs types (arrays, maps)
lynxkite-graph-analytics/src/lynxkite_graph_analytics/pytorch_model_ops.py CHANGED
@@ -130,69 +130,11 @@ def build_model(ws: workspace.Workspace, inputs: dict):
130
  for e in ws.edges:
131
  inputs[e.target].append(e.source)
132
  layers = []
133
-
134
-
135
- def build_model(cfg, device, dropout=None):
136
- F.triplet_margin_loss
137
- layers.append((pyg.nn.Linear(E, H), "x -> x"))
138
- layers.append((torch.nn.LayerNorm(H), "x -> x"))
139
- for i in range(cfg.attention_layers):
140
- layers.append(
141
- (torch.nn.MultiheadAttention(H, 1, batch_first=True), "x, x, x -> x")
142
- )
143
- # Pick values, not weights.
144
- layers.append(lambda res: res[0])
145
- layers.append(torch.nn.LayerNorm(H))
146
- # Just take the first token embedding after attention?
147
- layers.append(lambda res: res[:, 0, :])
148
- encoder = pyg.nn.Sequential("x", layers).to(device)
149
- for i in range(cfg.gnn_layers):
150
- layers.append((cfg.conv(E, H), "x, edge_index -> x"))
151
- if dropout:
152
- layers.append(torch.nn.Dropout(dropout))
153
- layers.append(cfg.activation())
154
- for i in range(cfg.mlp_layers - 1):
155
- layers.append((pyg.nn.Linear(E, H), "x -> x"))
156
- if dropout:
157
- layers.append(torch.nn.Dropout(dropout))
158
- layers.append(cfg.activation())
159
- layers.append((pyg.nn.Linear(E, H), "x -> x"))
160
- if cfg.predict == "remaining_steps":
161
- assert cfg.loss_fn != F.triplet_margin_loss, (
162
- "Triplet loss is only for embedding outputs."
163
- )
164
- layers.append((pyg.nn.Linear(E, 1), "x -> x"))
165
- elif cfg.predict == "tactics":
166
- assert cfg.loss_fn == F.cross_entropy, (
167
- "Use cross entropy for tactic prediction."
168
- )
169
- layers.append((pyg.nn.Linear(E, len(TACTICS)), "x -> x"))
170
- elif cfg.predict == "link_likelihood_for_states":
171
- pass # Just output the embedding.
172
- elif cfg.embedding["method"] != "learned":
173
- layers.append((pyg.nn.Linear(E, E), "x -> x"))
174
- m = pyg.nn.Sequential("x, edge_index", layers).to(device)
175
- if cfg.predict == "link_likelihood_for_states":
176
- # The comparator takes two embeddings (state and theorem) and predicts the link.
177
- layers = []
178
- layers.append(
179
- (
180
- lambda state, theorem: torch.cat([state, theorem], dim=1),
181
- "state, theorem -> x",
182
- )
183
- )
184
- for i in range(cfg.comparator_layers):
185
- layers.append((pyg.nn.Linear(E, H), "x -> x"))
186
- if dropout:
187
- layers.append(torch.nn.Dropout(dropout))
188
- layers.append(cfg.activation())
189
- assert cfg.loss_fn != F.triplet_margin_loss, (
190
- "Triplet loss is only for embedding outputs."
191
- )
192
- layers.append((pyg.nn.Linear(E, 1), "x -> x"))
193
- # Sigmoid activation at the end to get a probability.
194
- layers.append((torch.nn.Sigmoid(), "x -> x"))
195
- m.comparator = pyg.nn.Sequential("state, theorem", layers).to(device)
196
- if encoder and cfg.predict in ["nodes", "links", "links_for_states"]:
197
- m.encoder = encoder
198
  return m
 
130
  for e in ws.edges:
131
  inputs[e.target].append(e.source)
132
  layers = []
133
+ # TODO: Create layers based on the workspace.
134
+ sizes = {}
135
+ for k, v in inputs.items():
136
+ sizes[k] = v.size
137
+ layers.append((pyg.nn.Linear(sizes["x"], 1024), "x -> x"))
138
+ layers.append((torch.nn.LayerNorm(1024), "x -> x"))
139
+ m = pyg.nn.Sequential("x, edge_index", layers)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  return m