models icon indicating copy to clipboard operation
models copied to clipboard

Importing syntaxnet from Python

Open korkinof opened this issue 10 years ago • 5 comments

Hi guys, I've built syntaxnet and was able to run the demo. How do I import the package from python? I think I can see python wrappers in the build, but cannot seem to be able to import the whole thing. Can anyone help? Thanks in advance! Best, D.

korkinof avatar May 24 '16 18:05 korkinof

Hi Dimitrios,

We don't currently suggest a single official way to run SyntaxNet from Python. One simple approach is to spawn SyntaxNet as a subprocess, as done here. But you could wrap it in a Python module, or even call the TensorFlow graph from C++, without any Python.

Cheers, Daniel

andorardo avatar Jun 02 '16 13:06 andorardo

Hi andorado, Can you please provide some details about how to call the TensorFlow graph from C++, i read the tensorflow tutorials about it, but couldn't figure out how this could be applied to syntaxnet.

Hema414 avatar Nov 03 '16 12:11 Hema414

the currently recommended way to use syntaxnet from python is via DRAGNN

micimize avatar May 01 '17 02:05 micimize

Hi micimize,

I got the docker image started as described in the link, and then able to run the demo.sh. However, still cannot figure out how can I run the model from vanila python. Are there any resources that can help?

--Srinath

srinathperera avatar May 24 '17 04:05 srinathperera

@srinathperera I've only gotten it working via bazel and docker with the following BUILD:

py_binary(
    name = "app",
    main = "src/__main__.py",
    srcs = ["src/__main__.py"],
    deps = [":deps"],
)

py_library(
    name = "deps",
    deps = [
        "//dragnn/core:dragnn_bulk_ops",
        "//dragnn/core:dragnn_ops",
        "//dragnn/protos:spec_py_pb2",
        "//dragnn/python:graph_builder",
        "//dragnn/python:lexicon",
        "//dragnn/python:load_dragnn_cc_impl_py",
        "//dragnn/python:spec_builder",
        "//dragnn/python:visualization",
        "//syntaxnet:load_parser_ops_py",
        "//syntaxnet:parser_ops",
        "//syntaxnet:sentence_py_pb2",
        "@org_tensorflow//tensorflow:tensorflow_py",
        "@org_tensorflow//tensorflow/core:protos_all_py",
    ],
)

and Dockerfile:

FROM tensorflow/syntaxnet

ENV SYNTAXNETDIR=/opt/tensorflow
ENV WORKDIR=$SYNTAXNETDIR/syntaxnet/journal

RUN mkdir -p $WORKDIR/src

WORKDIR $WORKDIR

COPY src ./src
COPY data ./data
COPY requirements.txt ./
COPY BUILD            ./

RUN apt-get install -y coreutils
RUN python -m pip install -r requirements.txt

CMD /bin/bash -c "bazel run app"

micimize avatar May 29 '17 01:05 micimize