Commit 4364390a authored by Ivan Bogatyy's avatar Ivan Bogatyy Committed by calberti
Browse files

Release DRAGNN bulk networks (#2785)

* Release DRAGNN bulk networks
parent 638fd759
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Utils for loading resources (data files) from the SyntaxNet source tree.
The resources must be data dependencies of the relevant py_*() build target.
Example usage:
from syntaxnet.util import resources
data_blob = resources.GetSyntaxNetResource(
'syntaxnet/testdata/context.pbtxt')
"""
import os
# Absolute path to the root directory holding syntaxnet. Resource paths are
# interpreted relative to this path.
_ROOT_DIR = os.path.dirname( # .../
os.path.dirname( # .../syntaxnet/
os.path.dirname( # .../syntaxnet/util/
os.path.abspath(__file__)))) # .../syntaxnet/util/resources.py
def GetSyntaxNetResourceAsFile(path):
"""Returns a resource as an opened read-only file.
Args:
path: Relative path to the resource, which must be a Bazel data dependency.
Returns:
Opened read-only file pointing to resource data.
Raises:
IOError: If the resource cannot be loaded.
"""
path = os.path.join(_ROOT_DIR, path)
if os.path.isdir(path):
raise IOError('Resource "{}" is not a file'.format(path))
if not os.path.isfile(path):
raise IOError(
'Resource "{}" not found; is it a data dependency?'.format(path))
return open(path, 'rb')
def GetSyntaxNetResource(path):
"""Returns the content of a resource.
Args:
path: Relative path to the resource, which must be a Bazel data dependency.
Returns:
Raw content of the resource.
Raises:
IOError: If the resource cannot be loaded.
"""
with GetSyntaxNetResourceAsFile(path) as resource_file:
return resource_file.read()
# Copyright 2017 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for resources."""
from tensorflow.python.platform import googletest
from syntaxnet.util import resources
class ResourcesTest(googletest.TestCase):
"""Testing rig."""
def testInvalidResource(self):
for path in [
'bad/path/to/no/file',
'syntaxnet/testdata',
'syntaxnet/testdata/context.pbtxt',
]:
with self.assertRaises(IOError):
resources.GetSyntaxNetResource(path)
with self.assertRaises(IOError):
resources.GetSyntaxNetResourceAsFile(path)
def testValidResource(self):
path = 'syntaxnet/testdata/hello.txt'
self.assertEqual('hello world\n', resources.GetSyntaxNetResource(path))
with resources.GetSyntaxNetResourceAsFile(path) as resource_file:
self.assertEqual('hello world\n', resource_file.read())
if __name__ == '__main__':
googletest.main()
......@@ -16,11 +16,12 @@ limitations under the License.
// Features for whole Sentence objects. Contrast with SentenceFeature, which
// operates on tokens within Sentences.
#include "syntaxnet/feature_extractor.h"
#ifndef SYNTAXNET_WHOLE_SENTENCE_FEATURES_H_
#define SYNTAXNET_WHOLE_SENTENCE_FEATURES_H_
#include "syntaxnet/feature_extractor.h"
#include "syntaxnet/registry.h"
namespace syntaxnet {
// Type of feature functions whose focus is a whole sentence.
......@@ -30,6 +31,9 @@ typedef FeatureFunction<Sentence> WholeSentenceFeatureFunction;
#define REGISTER_WHOLE_SENTENCE_FEATURE_FUNCTION(name, type) \
REGISTER_SYNTAXNET_FEATURE_FUNCTION(WholeSentenceFeatureFunction, name, type)
DECLARE_SYNTAXNET_CLASS_REGISTRY("whole sentence feature function",
WholeSentenceFeatureFunction);
} // namespace syntaxnet
#endif // SYNTAXNET_WHOLE_SENTENCE_FEATURES_H_
Subproject commit 9026756727e7c6782ab89c181c80b2117bf78c05
Subproject commit c52cdc03a67ceae9ecc8c00025d3c60f54833e2d
/*
* The authors of this software are Rob Pike and Ken Thompson.
* Copyright (c) 1998-2002 by Lucent Technologies.
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
import %workspace%/tensorflow/.tf_configure.bazelrc
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true
build:win-cuda --define=using_cuda=true --define=using_cuda_nvcc=true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment