Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #54 & for registry.instantiate #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN mkdir -p /usr/share/man/man1 && \
COPY requirements.txt setup.py /app/
WORKDIR /app
RUN pip install --user -r requirements.txt --no-warn-script-location && \
pip install --user entmax && \
pip install --user entmax stanfordnlp && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps better moved to setup.py, like other dependencies. IIRC, entmax was special because it hardcoded PyTorch dependency in a weird way, so we had to control the order of its installation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I corrected as you commented.

python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt')"

# Cache the pretrained BERT model
Expand Down
4 changes: 2 additions & 2 deletions ratsql/resources/corenlp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import sys

import corenlp
import requests
from stanfordnlp.server import CoreNLPClient


class CoreNLP:
Expand All @@ -18,7 +18,7 @@ def __init__(self):

Direct URL: http://nlp.stanford.edu/software/stanford-corenlp-full-2018-10-05.zip
Landing page: https://stanfordnlp.github.io/CoreNLP/''')
self.client = corenlp.CoreNLPClient()
self.client = CoreNLPClient()

def __del__(self):
self.client.stop()
Expand Down
23 changes: 15 additions & 8 deletions ratsql/utils/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,29 @@ def construct(kind, config, unused_keys=(), **kwargs):
**kwargs)


def instantiate(callable, config, unused_keys=(), **kwargs):
def instantiate(invocable, config, unused_keys=(), **kwargs):
merged = {**config, **kwargs}
signature = inspect.signature(callable)
for name, param in signature.parameters.items():

if hasattr(invocable, '__init__'):
# to avoid inspecting ctor of parent class (if exists) instead of the target class's ctor
params = dict(inspect.signature(invocable.__init__).parameters)
params.pop('self', None)
else:
params = dict(inspect.signature(invocable).parameters)

for name, param in params.items():
if param.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.VAR_POSITIONAL):
raise ValueError(f'Unsupported kind for param {name}: {param.kind}')

if any(param.kind == inspect.Parameter.VAR_KEYWORD for param in signature.parameters.values()):
return callable(**merged)
if any(param.kind == inspect.Parameter.VAR_KEYWORD for param in params.values()):
return invocable(**merged)

missing = {}
for key in list(merged.keys()):
if key not in signature.parameters:
if key not in params:
if key not in unused_keys:
missing[key] = merged[key]
merged.pop(key)
if missing:
print(f'WARNING {callable}: superfluous {missing}', file=sys.stderr)
return callable(**merged)
print(f'WARNING {invocable}: superfluous {missing}', file=sys.stderr)
return invocable(**merged)