Reflection-based Word Attribute Transfer

Word embeddings, which often represent such analogic relations as king - man + woman queen, can be used to change a word’s attribute, including its gender. For transferring king into queen in this analogy-based manner, we subtract a difference vector man - woman based on the knowledge that king is male. However, developing such knowledge is very costly for words and attributes. In this work, we propose a novel method for word attribute transfer based on reflection mappings without such an analogy operation. Experimental results show that our proposed method can transfer the word attributes of the given words without changing the words that do not have the target attributes.

These relations can be used to transfer a certain attribute of a word, such as changing king into queen by transferring its gender.This transfer can be applied to perform data augmentation; for example, rewriting He is a boy to She is a girl.It can be used to generate negative examples for natural language inference, for example.We tackle a novel A naive way for word attribute transfer is to use a difference vector based on analogic relations, such as adding − −−−− → woman − −−→ man to −−→ king to obtain −−−→ queen.This requires explicit knowledge whether an input word is male or female; we have to add a difference vector to a male word and subtract it from a female word for the gender transfer.We also have to avoid changing words without gender attributes, such as is and a in the example above, since they are non-attribute words.Developing such knowledge is very costly for words and attributes in practice.In this work, we propose a novel framework for a word attribute transfer based on reflection that does not require explicit knowledge of the given words in its prediction.
The contribution of this work is two-fold: (1) We propose a word attribute transfer method that obtains a vector with an inverted binary attribute without explicit knowledge.(2) The proposed method demonstrates more accurate word attribute transfer for words that have target attributes than other baselines without changing the words that do not have the target attributes.

Word Attribute Transfer Task
In this task, we focus on modeling the binary attributes (e.g.male and female 1 ).Let x denote a word and let v x denote its vector representation.We assume that v x is learned in advance with an embedding model, such as skip-gram.In this task, we have two inputs, word x and vector z, which represent a certain target attribute, and output word t with the inverted attribute of x for z.In this paper, z is a 300-dimensional vector embedded from a target attribute ID using an embedding function of a deep learning framework.For example, given a set of attributes Z = {gender, antonym}, we assign different random vectors z gender for gender and z antonym for antonym, respectively.Let A denote a set of triplets (x, t, z), e.g., (man, woman, z gender ) ∈ A, and N denote a set of words without attribute z, e.g., (person, z gender ) ∈ N .This task transfers input word vector v x to target word vector v t by transfer function f z that inverts attribute z of v x : (1) The following property must be satisfied: (1) attribute words {x|(x, t, z) ∈ A} are transferred to their counterparts and (2) non-attribute words {x|(x, z) ∈ N } are not changed (transferred back into themselves).For instance with z gender , given input word man, gender attribute transfer f z gender (v man ) should result in a vector close to v woman .Given another input word person as x, the results should be v person .

Analogy-based Word Attribute Transfer
Analogy is a general idea that can be used for word attribute transfer.PMI-based word embedding, such as SGNS and GloVe, captures analogic relations, including Eq. 2 (Mikolov et al., 2013c;Levy and Goldberg, 2014a;Linzen, 2016).By rearranging Eq. 2, Eq. 3 is obtained: The analogy-based transfer function is where M is a set of words with a target attribute (e.g., male) and F is a set of words with an inverse attribute (e.g., female).d is a difference vector, such as v man − v woman .Eq. 4 indicates that the operation changes depending on whether input word x belongs to M or F. However, to transfer the word attribute by analogy, we need such explicit knowledge as attribute value (M, F or others) that is contained by the input word.
4 Reflection-based Word Attribute Transfer

Ideal Transfer without Knowledge
What is ideal transfer function f z for a word attribute transfer?The following are the ideal natures of such a transfer function: This function f z enables a word to be transferred without explicit knowledge because operation f z does not change depending on whether input word belongs to M or F. By combining Eqs. 5, 6 and 7, we obtain the following formulas: Hence, the ideal transfer function is a mapping that becomes an identity mapping when we apply it twice for any v.Such a mapping is called involution in geometry.For example, f : v → −v is one example of an involution.

Reflection
Reflection Ref a,c is an ideal function because this mapping is an involution: Reflection reverses the location between two vectors in a Euclidean space through an hyperplane called a mirror.Reflection is different from inverse mapping.When m and w are paired words, reflection can transfer v m and v w each other with identical reflection mapping as in Eqs. 5 and 6, but an inverse mapping cannot.Given vector v in Euclidean space R n , the formula for the reflection in the mirror is given: where a ∈ R n is a vector orthogonal to the mirror and c ∈ R n is a point through which the mirror passes.a and c are parameters that determine the mirror.We apply reflection to the word attribute transfer.We learn a mirror (hyperplane) in a pre-trained embedding space using training word pairs with binary attribute z (Fig. 2).Since the mirror is uniquely determined by two parameter vectors, a and c, we estimate a and c from target attribute z using fully connected multi-layer perceptrons: where θ is a set of trainable parameters of MLP θ .
Here, θ 1 and θ 2 are optimized for each attribute dataset.Transferred vector v y is obtained by inverting attribute z of v x by reflection: Reflection with a mirror by Eqs. 13 and 14 assumes a single mirror that only depends on z.Previous discussion assumed pairs that share a stable pair, such as king and queen.However, since gendered words often do not come in pairs, gender is not stable enough to be modeled by a single mirror.For example, although actress is exclusively feminine, actor is clearly neutral in many cases.Thus, actor is not obviously a masculine counterpart like king.In fact, bias exists in gender words in the embedding space (Zhao et al., 2018;Kaneko and Bollegala, 2019).This phenomenon can occur not only with gender attributes but also with other attributes.The single mirror assumption forces the mirror to be a hyperplane that goes through the midpoints for all the word vector pairs.However, the vector pair actor-actress shown on the right in Fig. 3 cannot be transferred well since the single mirror (the green line) does not satisfy this constraint due to the bias of the embedding space.To solve this problem, we propose parameterized mirrors, based on the idea of using different mirrors for different words.We define mirror parameters a and c using word vector v x to be transferred in addition to attribute vector z: where [•; •] indicates the vector concatenation in the column.The parameterized mirrors are expected to work more flexibly on different words than a single mirror because parameterized mirrors dynamically determine similar mirrors for similar words.For instance, as shown in Fig. 3, suppose we learned the mirror (the blue line) that transfers v hero to v heroine in advance.If input word vector v actor resembles v hero , a mirror that resembles the one for v hero should be derived and used for the transfer.
On the other hand, the reflection works as an identity mapping for a vector on the mirror (e.g., v person in Fig 3).That is, the proposed method assumes that non-attribute word vectors are located on the mirror.Since we used a 300-dimensional embedded space in the experiment, we assume that the non-attribute word vector exists in a 299dimensional subspace.
Here, it should be noted that Eq. 11 may not hold for parameterized mirrors.In reflection with a single mirror, it is true that v = Ref a,c ( Ref a,c (v)).However, with the v-parameterized reflection Ref a v ,c v (v), this is not guaranteed.Because mirror parameters a v and c v depend on an input word vector as Eqs.16 and 17.Thus, we exclude this constraint and employ the constraints given by Eqs.5-7 for our loss function.
The following property must be satisfied in word attribute transfer: (1) words with attribute z are transferred and (2) words without it are not transferred.Thus, loss L(θ 1 , θ 2 ) is defined: where Eq. 18 is a term that draws target word vector v t i closer to corresponding transferred vector v y i and Eq.19 is a term that prevents words without a target attribute from being moved by transfer function.v y is the output of a reflection (Eq.15).

Experiment
We evaluated the performance of the word attribute transfer using data with four different attributes.
We used 300-dimensional word2vec and GloVe as the pre-trained word embedding.We used four different datasets of word pairs with four binary attributes: Male-Female, Singular-Plural, Capital-Country, and Antonym (Table 1).These word pairs were collected from analogy test sets (Mikolov et al., 2013a;Gladkova et al., 2016)

Evaluation Metrics
We measured the accuracy and stability performances of the word attribute transfer.The accuracy measures how many input words in A test were transferred correctly to the corresponding target words.The stability score measures how many words in N test were not mapped to other words.For example, in the Male-Female transfer, given man, the transfer is regarded as correct if woman is the closest word to the transferred vector; otherwise it is incorrect.Given person, the transfer is regarded as correct if person is the closest word to the transferred vector; otherwise it is incorrect.The accuracy and stability scores are calculated by the following formula: where V is the vocabulary of the word embedding model and cos(v y , v k ) is the cosine similarity measure, defined as:

Methods and Configurations
In our experiment, we compared our proposed method with the following baseline methods2 : REF Reflection-based word attribute transfer with a single mirror.We used a fully connected 2-layer MLP with 300 hidden units and ReLU (Glorot et al., 2011) to estimate a and c.
REF+PM Reflection-based word attribute transfer with parameterized mirrors.We used the same architecture of MLP as the REF.
MLP Fully connected MLP with 300 hidden units and ReLU: v y = MLP([v x ; z]).The highest accuracy models in SGNS are a 2-layer MLP for Capital-Country and 3-layer MLP for the other datasets.The highest accuracy models in GloVe are a 2-layer MLP for Singular-Plural and 3-layer MLP for the other datasets.
DIFF Analogy-based word attribute transfer with a difference vector: d = v m − v w , where m and w are in the training data of A. We chose d that achieved the best accuracy in the validation data of A. We determined whether to add or subtract d to v x based on the explicit knowledge (Eq.4).DIFF + and DIFF − transfer with a difference vector regardless of the explicit knowledge.+ and − add or subtract the difference vector to any input word vector.
MEANDIFF Analogy-based word attribute transfer with a mean difference vector d: d = We determined whether to add or subtract d to v x based on the explicit knowledge (Eq.4).
For proposed methods, we used the Adam optimizer (Kingma and Ba, 2015) with α = 10 −4 for Male-Female, Singular-Plural and Capital-Country, and α = 15 −3 for Antonym (the other hyperparameters were the same as the original one (Kingma and Ba, 2015)).We did not use such regularization methods as dropout (Srivastava et al., 2014) or batch normalization (Ioffe and Szegedy, 2015) because they did not show any improvement in our pilot test.We implemented REF, REF+PM and MLP with Chainer (Tokui et al., 2019), which is one of the best deep learning frameworks.

Evaluation in Accuracy and Stability
Table 2 shows the accuracy and stability results.Different pre-trained word embeddings GloVe or word2vec gave similar results.REF+PM achieved the best accuracy among the methods that did not use explicit attribute knowledge.For example, the accuracy of REF+PM was 76% in Capital-Country, but the accuracy of DIFF + was 26%.For stability, reflection-based transfers achieved outstanding stability scores that exceeded 99%.The results show that our proposed method transfers an input word if it has a target attribute and does not transfer an input word with better score than the baselines otherwise, even though the proposed method does not use attribute knowledge of the input words.MLP worked poorly both in accuracy and stability.On the antonym dataset, although the transfer accuracy by the proposed method was a bit lower than that by MLP, the proposed methods stability was 100% and that of MLP was extremely poor: about 1%.
We investigated the relation between the training data size of the non-attribute words, and the stability of the learning-based methods by conducting an additional experiment that varied |N train |.The stability scores by MLP did not improve (Table 3).On the other hand, REF+PM achieved high stability scores with |N train | = 0 and maintained the accuracy.We hypothesized that the high stability came from the distance between the word and its mirror.If non-attribute words are distributed on the mirror, they will not be transferred.We investigated the distance between input word vector v x and its mirror (Fig. 4).The result shows that nonattribute words are close to the mirror, and attribute words are distributed away from it.In Male-Female and Singular-Plural, the distance is not significantly farther than Antonym and Capital-Country.If the distance between paired words is very small, the distance between the word and its mirror is also small.Fig. 5 shows the distribution of the distance between input v x and target word vector v t .
The distance of Male-Female and Singular-Plural is much smaller than Capital-Country and Antonym.

Visualization of Parameterized Mirrors
Figure 6 shows the t-SNE results of mirror parameter a obtained for the test words.Paired mirror, (a x , a t ), is connected by a line segment.Fig. 6 suggests that the mirror parameters of the paired words are similar to each other and that those with the attribute form a cluster; words with the same attribute have similar mirror parameters a.

Transfer Example
Table 4 shows the gender transfer results for a tiny example sentence.Here the attribute transfer was applied to every word in the sentence.MLP made many wrong transfers.Analogy-based transfers can transfer only in one direction.REF+PM can transfer only attribute words.Table 5 shows that words with different target attributes were transferred by each reflection-based transfer.

Related Work
The theory of analogic relations in word embeddings has been widely discussed (Levy and Goldberg, 2014b;Arora et al., 2016;Gittens et al., 2017;Ethayarajh et al., 2019;Allen and Hospedales, 2019;Linzen, 2016).In our work, we focus on the analogic relations in a word embedding space and propose a novel framework to obtain a word vector with inverted attributes.The style transfer task (Niu et al., 2018;Prabhumoye et al., 2018;Logeswaran et al., 2018;Jain et al., 2019;Dai et al., 2019;Lample et al., 2019) resembles ours.In style transfer, the text style of the input sentences is changed.For instance, Jain et al. (2019) transferred from formal to informal sentences.These style transfer tasks use sentence pairs; our word attribute transfer task uses word pairs.Style transfer changes sentence styles, but our task changes the word attributes.Soricut and Och (2015) studied morphological transformation based on character information.Our work aims for more general attribute transfer, such as gender transfer and antonym, and is not limited to morphological transformation.

Conclusion
This research aims to transfer word binary attributes (e.g., gender) for applications such as data augmentation of a sentence.We can transfer the word attribute with analogy of word vectors, but it requires explicit knowledge whether the input word has the attribute or not (e.g., man ∈ gender, woman ∈ gender, person / ∈ gender).The proposed method transfers binary word attributes using reflectionbased mappings and keeps non-attribute words unchanged, without attribute knowledge in inference time.The experimental results showed that the proposed method outperforms analogy-based and MLP baselines in transfer accuracy for attribute words and stability for non-attribute words.

Figure 1 :
Figure 1: Examples of word attribute transfer task that transfers any word associated with certain attributes: word attribute transfer.A naive way for word attribute transfer is to use a difference vector based on analogic relations, such as adding − −−−− → woman − −−→ man to −−→ king to obtain −−−→ queen.This requires explicit knowledge whether an input word is male or female; we have to add a difference vector to a male word and subtract it from a female word for the gender transfer.We also have to avoid changing words without gender attributes, such as is and a in the example above, since they are non-attribute words.Developing such knowledge is very costly for words and attributes in practice.In this work, we propose a novel framework for a word attribute transfer based on reflection that does not require explicit knowledge of the given words in its prediction.The contribution of this work is two-fold: (1) We propose a word attribute transfer method that obtains a vector with an inverted binary attribute without explicit knowledge.(2) The proposed method demonstrates more accurate word attribute transfer for words that have target attributes than other baselines without changing the words that do not have the target attributes.
Figure 2: Reflection-based word attribute transfer with a single mirror

Figure 4 :Figure 5 :Figure 6 :
Figure 4: Distribution of distance between input word vector and its mirror |(vx−c)•a| a learned by REF+PM.Non-attribute words are close to the mirror, and attribute words are distributed away from it.
(Nguyen et al., 2017) antonyms were taken from the literature(Nguyen et al., 2017).For non-attribute dataset N , we sampled words from the vocabulary of word embedding.We sampled from 4 to 50 words for training and 1000 for the test (|N test | = 1000).

Table 2 :
Results in accuracy and stability scores: MF, SP, CC, and AN are datasets.

Table 3 :
Relation among size of |N train | and stability of learning-based methods

Table 4 :
Comparison of gender transfers.Each method transfers words in a sentence one by one.

Table 5 :
Transfer of different attributes with REF+PM + MFthe rich actress wants to visit the beautiful city in tokyo.+ SP the rich actresses wants to visit the beautiful cities in tokyo.+ CC the rich actresses wants to visit the beautiful cities in japan.+ AN the poor actresses wants to visit the beautiful cities in japan.