syntaxnet_link_feature_extractor.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2017 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // =============================================================================
  15. #ifndef NLP_SAFT_OPENSOURCE_DRAGNN_COMPONENTS_SYNTAXNET_SYNTAXNET_LINK_FEATURE_EXTRACTOR_H_
  16. #define NLP_SAFT_OPENSOURCE_DRAGNN_COMPONENTS_SYNTAXNET_SYNTAXNET_LINK_FEATURE_EXTRACTOR_H_
  17. #include <string>
  18. #include <vector>
  19. #include "dragnn/protos/spec.pb.h"
  20. #include "syntaxnet/embedding_feature_extractor.h"
  21. #include "syntaxnet/parser_state.h"
  22. #include "syntaxnet/parser_transitions.h"
  23. #include "syntaxnet/task_context.h"
  24. namespace syntaxnet {
  25. namespace dragnn {
  26. // Provides feature extraction for linked features in the
  27. // WrapperParserComponent. This re-ues the EmbeddingFeatureExtractor
  28. // architecture to get another set of feature extractors. Note that we should
  29. // ignore predicate maps here, and we don't care about the vocabulary size
  30. // because all the feature values will be used for translation, but this means
  31. // we can configure the extractor from the GCL using the standard
  32. // neurosis-lib.wf syntax.
  33. //
  34. // Because it uses a different prefix, it can be executed in the same wf.stage
  35. // as the regular fixed extractor.
  36. class SyntaxNetLinkFeatureExtractor : public ParserEmbeddingFeatureExtractor {
  37. public:
  38. SyntaxNetLinkFeatureExtractor() : ParserEmbeddingFeatureExtractor("link") {}
  39. ~SyntaxNetLinkFeatureExtractor() override {}
  40. const string ArgPrefix() const override { return "link"; }
  41. // Parses the TaskContext to get additional information like target layers,
  42. // etc.
  43. void Setup(TaskContext *context) override;
  44. // Called during InitComponentProtoTask to add the specification from the
  45. // wrapped feature extractor as LinkedFeatureChannel protos.
  46. void AddLinkedFeatureChannelProtos(ComponentSpec *spec) const;
  47. private:
  48. // Source component names for each channel.
  49. std::vector<string> channel_sources_;
  50. // Source layer names for each channel.
  51. std::vector<string> channel_layers_;
  52. // Source translator name for each channel.
  53. std::vector<string> channel_translators_;
  54. };
  55. } // namespace dragnn
  56. } // namespace syntaxnet
  57. #endif // NLP_SAFT_OPENSOURCE_DRAGNN_COMPONENTS_SYNTAXNET_SYNTAXNET_LINK_FEATURE_EXTRACTOR_H_