# Task-Aware Feature Composition for Few-Shot Relation Classification
## 4 Methodology
### Task-Aware Feature Composition  
Up until now, we assumed the feature extractor \(f_{\phi}(x)\) and the prototype \(c^{n}\) to be task-independent. However, a dynamic task-aware feature extractor should be better suited for finding correct associations between given sample set relation prototypes and query samples. In other words, if there is a meta-task that its relation types are difficult to distinguish, the model needs to construct a more finely tailored feature set rather than a shared feature set across all meta-tasks. To achieve this, we first capture task-specific information by employing a task embedding learning module on top of relation prototypes. Then, we design two guiding modes for composing task-aware features. **Task Embedding Learning. ** Since each meta-task has a different set of relation types, in order to capture task-specific information, we place a task embedding a learning module on top of relation prototypes. Formally, given relation prototypes \(\{c^{1},c^{2},\dots,c^{N}\}\), we first concatenate these prototypes and treat them as a sequence, then we place a CNN encoder following the max pooling operation on top of the sequence. Finally, we can obtain the task embedding \(o\), which contains task-specific information,  
\[o=max(Conv(c^{1};c^{2};\dots;c^{N})),\;o\in\mathbb{R}^{d_{h}} \tag{16}\]  
where \(d_{h}\) indicates the number of convolutional filters. After obtaining the task embedding, two guiding modes are proposed to utilize the embedding to guide feature composition. **Mode 1: Task-gated mechanism. ** A task-gated mechanism is a specially designed unit for guiding feature composition, which is inspired by [30,31]. In particular, we propose a task-gate to select task-specific representations by controlling the transformation scale of query and prototype representations. Given a query representation \(\widetilde{q}\in\mathbb{R}^{4d_{h}}\), relation prototypes \(\{c^{1},c^{2},\dots,c^{N}\}\), \(c^{n}\in\mathbb{R}^{4d_{h}}\), and task embedding \(o\in\mathbb{R}^{d_{h}}\), we first employ a fully connected layer to transform \(\widetilde{q}\), \(c^{n}\) into the same space of \(o\). Then, the task-gate is placed on top of both query and relation prototypes for building task-specific representations. The computing equations are as follows:  
\[\widetilde{q}^{\prime}=g_{t}\odot Relu(W_{2}\widetilde{q}) \tag{17}\]  
\[c^{n\prime}=g_{t}\odot Relu(W_{2}c^{n}) \tag{18}\]  
\[g_{t}=\sigma(o), \tag{19}\]  
where \(W_{2}\in\mathbb{R}^{d_{h}\times 4d_{h}}\), \(g_{t}\) represents the task-gate, \(\sigma\) denotes the sigmoid function, and \(\widetilde{q}^{\prime}\) and \(c^{n\prime}\) represent the task-aware representation of query and relation prototypes. In Equations (16)-(18), the task-gate \(g_{t}\) controls the transformations of query representation and relation prototypes under the guidance of the learned task embedding. This enables the task embedding to guide the encoding of task-specific features and block the task-irrelevant information. **Mode 2: Gated Feature Combination. ** Gated feature combination utilizes task-specific information from another perspective. It treats the task embedding \(o\) as task-specific features and uses a gated function to selectively combine the features with query representation and relation prototypes. For \(o\), it provides a summary of the meta-task. Though this evidence is valuable to the prediction process, we must mitigate the influence of the task embedding since the prediction should still be made primarily based on the query representation and relation prototypes.