How to teach Transformers to care about word order

New position encoding scheme improves state-of-the-art performance on several natural-language-processing tasks.

The Transformer is a neural-network architecture that has proven extremely useful for natural-language-processing tasks because it can recognize long-range dependencies. It could, for instance, recognize that in a sentence that includes the word “rented”, the word “flat” is more likely to mean “apartment” than it would be otherwise, even if “rented” is the second word in the sentence and “flat” the 10th.

In its most basic form, the Transformer is indifferent to word order. It can recognize the relationship between “rented” and “flat”, but it doesn’t care which comes first.

Word order, however, can make a big difference to meaning. Consider, for instance, the sentences “We rented a small but clean, well-equipped two-bed flat” and “We rented a small but clean, well-equipped flat-bed truck”.

Position embedding.png
These images map 252 words of an input text sequence (y-axis) against the 512 latent position features identified by two different position-encoding schemes. Lighter colors indicate higher values for features, darker colors lower values. FLOATER (bottom) produces a more regular encoding than an earlier scheme (top), which also learns its position feature set from training data. The vertical lines toward the bottom of the top visualization indicate that the encoding model is simply using the same encoding for input sequences longer than those it saw during training, while FLOATER’s smooth gradation from light to dark demonstrates that its encoding generalizes easily to longer sequences.

Starting with the paper that introduced the Transformer, researchers have proposed a series of position encoders that inject word-order information into the Transformer model. But last week, at the International Conference on Machine Learning, we presented a new position encoder that enables better performance than its predecessors on a range of natural-language-processing (NLP) tasks.

We designed our position encoder so that it can be integrated into existing Transformer models, conferring its benefits to NLP systems that already have been trained extensively on large data sets.

Before the Transformer was introduced in 2017, the most popular architecture for NLP was the long short-term memory, or LSTM. LSTMs process sequenced inputs in order, and each output reflects both the inputs and the outputs that preceded it.

LSTMs are very good at inferring local relationships — a word’s relationships, both syntactic and semantic, with the two or three words that immediately precede it — but they’re not as good at modeling long-range dependencies. That’s where the Transformer excels.

Position encodings are an attempt to achieve the best of both worlds: an awareness of long-range dependencies and a sensitivity to local word order. The ideal position encoding should have three properties:

  1. It should be able to handle sequences of arbitrary length; that is, it shouldn’t be locked in to some maximum sequence length.
  2. It should be learnable from training data; different encodings may work better for different tasks.
  3. It should be efficient; adding position encoding shouldn’t unreasonably inflate the size of the neural model.

Past position encoding schemes have met at best two of these criteria. For instance, the original Transformer paper proposed an encoding based on a family of sinusoidal functions; that encoding remains popular, but it is not learnable.

Our scheme, which we call FLOATER, is the first to meet all three criteria.

The naïve way to encode position would be simply to assign successive numbers to successive words in an input sequence. But this has drawbacks in a machine learning context. If at runtime the model sees a sequence of a length it did not encounter during training, it will be flummoxed about how to proceed.

So most position encoding schemes instead use position vectors, which carry information that can be used to deduce the relative positions of two inputs. If those schemes are fully learnable, however, they tend to inflate the model size; or, to keep model inflation under control, they limit the distances across which relative position can be compared.

Functional approach

Instead of learning to directly compute a position vector from each word in an input sequence, FLOATER learns a function that computes each word’s position vector from that of the word that preceded it.

Learning a general function rather than direct mappings makes FLOATER much more space efficient than other learnable encoding schemes. But a general function can also be applied to any word in a sequence, regardless of its position, so FLOATER is indifferent to sequence length.

Any given manually engineered position function — such as the sinusoidal functions proposed in the original Transformer paper — can be thought of as a special case of the general FLOATER function. So in a pretrained network, we can simply substitute FLOATER for any such function and then fine-tune it on a small set of training data.

Past work on position encoding has shown that re-encoding position information at every layer of a Transformer network improves performance on NLP tasks. If we allowed FLOATER to learn a different function for every layer, the model size would again begin to inflate.

So instead, we learn a single function that is applied at every layer. This results in different position encodings at each layer, however, because the inputs are different. Our experiments indicate that this approach strikes a good balance between model size and performance improvements.

In one set of experiments, we compared our position encoder to its two leading predecessors on four different machine translation tasks and found that it delivered the best results across the board.

In another set of experiments, we added our position encoder to Transformer models that had previously been trained on three different language-understanding and question-answering tasks.

Of 23 distinct tasks, the addition of our position encoder improved performance on 21. The two on which its performance fell slightly short were low-data versions of tasks on which, with larger sets of training data, it improved performance.

Related content

GB, London
How can Amazon improve the advertising experience for customers around the world? How can we help advertisers and customers find each other in a meaningful way? Amazon Advertising creates and transforms the connection between retailers/service providers and customers. Our teams strive to reinvent the way advertisers and agencies build brands and drive performance in their advertising. By using Amazon's foundation in e-commerce, we help brands connect with the right customers through creative solutions and formats across screens and devices, and in the physical world. Amazon Advertising seeks a Data Scientist with strong Data Analysis skills to join the ADSP engineering team split across Edinburgh and London. We make Guidance products that help optimise our customer's advertising campaign workflows and performance. As a scientist on the team, you will be involved in many aspects of the process - from idea generation, business analysis and scientific research, through to development - giving you a real sense of ownership. The systems that you help to build will operate at massive scale to advertising customers around the world. Our ideal candidate is an experienced Data scientist who has a track-record of performing analysis, applying statistical techniques and building basic ML models to solve real business problems, who has great leadership and communication skills, and who is motivated to achieve results in a fast-paced environment. Key job responsibilities Rapidly design, prototype and test many possible hypotheses in a high-ambiguity environment, making use of both quantitative analysis and business judgment. Collaborate with software engineering teams to integrate successful experimental results into large-scale, highly complex Amazon production systems. Report results in a manner which is both statistically rigorous and compellingly relevant, exemplifying good scientific practice in a business environment. Promote the culture of experimentation at Amazon.
US, NY, New York
Amazon is looking for a passionate, talented, and inventive Applied Scientist with a strong machine learning background to help build industry-leading language technology. AWS Utility Computing (UC) provides product innovations — from foundational services such as Amazon’s Simple Storage Service (S3) and Amazon Elastic Compute Cloud (EC2), to consistently released new product innovations that continue to set AWS’s services and features apart in the industry. As a member of the UC organization, you’ll support the development and management of Compute, Database, Storage, Internet of Things (Iot), Platform, and Productivity Apps services in AWS, including support for customers who require specialized security solutions for their cloud services. Our mission is to provide a delightful experience to Amazon’s customers by pushing the envelope in Natural Language Processing (NLP), Generative AI, Large Language Model (LLM), Natural Language Understanding (NLU), Machine Learning (ML), Retrieval-Augmented Generation, Responsible AI, Agent, Evaluation, and Model Adaptation. As part of our AI team in Amazon AWS, you will work alongside internationally recognized experts to develop novel algorithms and modeling techniques to advance the state-of-the-art in human language technology. Your work will directly impact millions of our customers in the form of products and services, as well as contributing to the wider research community. You will gain hands on experience with Amazon’s heterogeneous text and structured data sources, and large-scale computing resources to accelerate advances in language understanding. The Science team at AWS Bedrock builds science foundations of Bedrock, which is a fully managed service that makes high-performing foundation models available for use through a unified API. We are adamant about continuously learning state-of-the-art NLP/ML/LLM technology and exploring creative ways to delight our customers. In our daily job we are exposed to large scale NLP needs and we apply rigorous research methods to respond to them with efficient and scalable innovative solutions. At AWS Bedrock, you’ll experience the benefits of working in a dynamic, entrepreneurial environment, while leveraging AWS resources, one of the world’s leading cloud companies and you’ll be able to publish your work in top tier conferences and journals. We are building a brand new team to help develop a new NLP service for AWS. You will have the opportunity to conduct novel research and influence the science roadmap and direction of the team. Come join this greenfield opportunity! About the team Diverse Experiences AWS values diverse experiences. Even if you do not meet all of the qualifications and skills listed in the job description, we encourage candidates to apply. If your career is just starting, hasn’t followed a traditional path, or includes alternative experiences, don’t let it stop you from applying. Why AWS? Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform. We pioneered cloud computing and never stopped innovating — that’s why customers from the most successful startups to Global 500 companies trust our robust suite of products and services to power their businesses. Inclusive Team Culture Here at AWS, it’s in our nature to learn and be curious. Our employee-led affinity groups foster a culture of inclusion that empower us to be proud of our differences. Ongoing events and learning experiences, including our Conversations on Race and Ethnicity (CORE) and AmazeCon (gender diversity) conferences, inspire us to never stop embracing our uniqueness. Mentorship & Career Growth We’re continuously raising our performance bar as we strive to become Earth’s Best Employer. That’s why you’ll find endless knowledge-sharing, mentorship and other career-advancing resources here to help you develop into a better-rounded professional. Work/Life Balance We value work-life harmony. Achieving success at work should never come at the expense of sacrifices at home, which is why we strive for flexibility as part of our working culture. When we feel supported in the workplace and at home, there’s nothing we can’t achieve in the cloud.
US, CA, Sunnyvale
The Artificial General Intelligence (AGI) team is looking for a highly skilled and experienced Senior Applied Scientist, to lead the development and implementation of cutting-edge algorithms and models for supervised fine-tuning and reinforcement learning through human feedback; with a focus across text, image, and video modalities. As a Senior Applied Scientist, you will play a critical role in driving the development of Generative AI (GenAI) technologies that can handle Amazon-scale use cases and have a significant impact on our customers' experiences. Key job responsibilities - Collaborate with cross-functional teams of engineers, product managers, and scientists to identify and solve complex problems in GenAI - Design and execute experiments to evaluate the performance of different algorithms and models, and iterate quickly to improve results - Think big about the arc of development of GenAI over a multi-year horizon, and identify new opportunities to apply these technologies to solve real-world problems - Communicate results and insights to both technical and non-technical audiences, including through presentations and written reports - Mentor and guide junior scientists and engineers, and contribute to the overall growth and development of the team
JP, 13, Tokyo
Amazon Japan is seeking an experienced Sr. Data Scientist to join our growing team. In this critical role, you will leverage your strong quantitative and analytical skills to drive data-driven insights that shape our FMCG (fast-moving consumer goods) business and other key strategic initiatives. Your responsibilities will include: - Solving complex, ambiguous business problems using appropriate statistical methodologies, modeling techniques, and data science best practices to lead business insights for FMCG business growth. You will work closely with cross-functional partners to translate business requirements into actionable data science solutions. - Designing and implementing scalable, reliable, and efficient data pipelines to extract valuable insights from diverse data sources. This includes making appropriate trade-offs between short-term and long-term needs. - Communicating your findings and recommendations clearly and persuasively to technical and non-technical stakeholders. You will document your work to the highest standards and ensure your solutions have a measurable impact on the business. - Mentoring and developing more junior data scientists on your team. You will actively participate in the hiring process and contribute to the growth of Amazon's data science community. - Staying abreast of the latest advancements in data science and applying innovative techniques where appropriate to tackle challenging business problems.
US, WA, Seattle
We are seeking a talented applied researcher to join the Whole Page Planning and Optimization (WPPO) Science team in Search. The latest data from Business Insider shows that almost 50% of online shoppers visit Amazon first. The Search WPPO Science team is responsible for developing reinforcement learning systems for the next generation Amazon shopping experience and delivering it to millions of customers. We believe that shopping on Amazon should be simple, delightful, and full of WOW moments for EVERYONE, whether you are technically savvy or new to online shopping. As an Applied Scientist, you will be working closely with a team of applied scientists and engineers to build systems that shape the future of Amazon's shopping experience by automatically generating relevant content and building a whole page experience that is coherent, dynamic, and interesting. You will improve ranking and optimization in our algorithm. You will participate in driving features from idea to deployment, and your work will directly impact millions of customers. You are going to love this job because you will: * Apply state-of-the-art Machine Learning (ML) algorithms, including Deep Learning and Reinforcement Learning, to improve hundreds of millions of customers’ shopping experience. * Have measurable business impact using A/B testing. * Work in a dynamic team that provides continuous opportunities for learning and growth. * Work with leaders in the field of machine learning.
US, WA, Bellevue
Conversational AI ModEling and Learning (CAMEL) team is part of Amazon Devices organization where our mission is to build a best-in-class Conversational AI that is intuitive, intelligent, and responsive, by developing superior Large Language Models (LLM) solutions and services which increase the capabilities built into the model and which enable utilizing thousands of APIs and external knowledge sources to provide the best experience for each request across millions of customers and endpoints. We are looking for a passionate, talented, and resourceful Applied Scientist in the field of LLM, Artificial Intelligence (AI), Natural Language Processing (NLP), Recommender Systems and/or Information Retrieval, to invent and build scalable solutions for a state-of-the-art context-aware conversational AI. A successful candidate will have strong machine learning background and a desire to push the envelope in one or more of the above areas. The ideal candidate would also have hands-on experiences in building Generative AI solutions with LLMs, enjoy operating in dynamic environments, be self-motivated to take on challenging problems to deliver big customer impact, moving fast to ship solutions and then iterating on user feedback and interactions. Key job responsibilities As an Applied Scientist, you will leverage your technical expertise and experience to collaborate with other talented applied scientists and engineers to research and develop novel algorithms and modeling techniques to reduce friction and enable natural and contextual conversations. You will analyze, understand and improve user experiences by leveraging Amazon’s heterogeneous data sources and large-scale computing resources to accelerate advances in artificial intelligence. You will work on core LLM technologies, including Prompt Engineering and Optimization, Supervised Fine-Tuning, Learning from Human Feedback, Evaluation, Self-Learning, etc. Your work will directly impact our customers in the form of novel products and services.
US, WA, Bellevue
Conversational AI ModEling and Learning (CAMEL) team is part of Amazon Artificial General Intelligence (AGI) organization where our mission is to create a best-in-class Conversational AI that is intuitive, intelligent, and responsive, by developing superior Large Language Models (LLM) solutions and services which increase the capabilities built into the model and which enable utilizing thousands of APIs and external knowledge sources to provide the best experience for each request across millions of customers and endpoints. We are looking for a passionate, talented, and resourceful Applied Scientist in the field of LLM, Artificial Intelligence (AI), Natural Language Processing (NLP), Recommender Systems and/or Information Retrieval, to invent and build scalable solutions for a state-of-the-art context-aware conversational AI. A successful candidate will have strong machine learning background and a desire to push the envelope in one or more of the above areas. The ideal candidate would also have hands-on experiences in building Generative AI solutions with LLMs, enjoy operating in dynamic environments, be self-motivated to take on challenging problems to deliver big customer impact, moving fast to ship solutions and then iterating on user feedback and interactions. Key job responsibilities As an Applied Scientist, you will leverage your technical expertise and experience to collaborate with other talented applied scientists and engineers to research and develop novel algorithms and modeling techniques to reduce friction and enable natural and contextual conversations. You will analyze, understand and improve user experiences by leveraging Amazon’s heterogeneous data sources and large-scale computing resources to accelerate advances in artificial intelligence. You will work on core LLM technologies, including Supervised Fine-Tuning (SFT), In-Context Learning (ICL), Learning from Human Feedback (LHF), etc. Your work will directly impact our customers in the form of novel products and services.
IL, Tel Aviv
Are you an inventive, curious, and driven Applied Scientist with a strong background in AI and Deep Learning? Join Amazon’s AWS Multimodal generative AI science team and be a catalyst for groundbreaking advancements in Computer Vision, Generative AI, and foundational models. As part of the AWS Multimodal generative AI science team, you’ll lead innovative research projects, develop state-of-the-art algorithms, and pioneer solutions that will directly impact millions of Amazon customers. Leveraging Amazon’s vast computing power, you’ll work alongside a supportive and diverse group of top-tier scientists and engineers, contributing to products that redefine the industry. Key job responsibilities * Lead research initiatives in Multimodal generative AI, pushing the boundaries of model efficiency, accuracy, and scalability. * Design, implement, and evaluate deep learning models in a production environment. * Collaborate with cross-functional teams to transfer research outcomes into scalable AWS services. * Publish in top-tier conferences and journals, keeping Amazon at the forefront of innovation. * Mentor and guide other scientists and engineers, fostering a culture of scientific curiosity and excellence.
US, WA, Seattle
The Search Supply & Experiences team, within Sponsored Products, is seeking an Applied Scientist to solve challenging problems in natural language understanding, personalization, and other areas using the latest techniques in machine learning. In our team, you will have the opportunity to create new ads experiences that elevate the shopping experience for our hundreds of millions customers worldwide. As an Applied Scientist, you will partner with other talented scientists and engineers to design, train, test, and deploy machine learning models. You will be responsible for translating business and engineering requirements into deliverables, and performing detailed experiment analysis to determine how shoppers are responding to your changes. We are looking for candidates who thrive in an exciting, fast-paced environment and who have a strong personal interest in learning, researching, and creating new technologies with high customer impact. Key job responsibilities As an Applied Scientist on the Search Supply & Experiences team you will: - Perform hands-on analysis and modeling of enormous datasets to develop insights that increase traffic monetization and merchandise sales, without compromising the shopper experience. - Drive end-to-end machine learning projects that have a high degree of ambiguity, scale, and complexity. - Build machine learning models, perform proof-of-concept, experiment, optimize, and deploy your models into production; work closely with software engineers to assist in productionizing your ML models. - Run A/B experiments, gather data, and perform statistical analysis. - Establish scalable, efficient, automated processes for large-scale data analysis, machine-learning model development, model validation and serving. - Stay up to date on the latest advances in machine learning. About the team We are a customer-obsessed team of engineers, technologists, product leaders, and scientists. We are focused on continuous exploration of contexts and creatives where advertising delivers value to shoppers and advertisers. We specifically work on new ads experiences globally with the goal of helping shoppers make the most informed purchase decision. We obsess about our customers and we are continuously innovating on their behalf to enrich their shopping experience on Amazon
US, WA, Seattle
We are seeking a highly skilled economist to measure and understand how each Customer Service activity impacts customers. This candidate's analysis will assist teams across Amazon to prioritize defect elimination efforts and optimize how we respond to customer contacts. This candidate will partner closely with our product, program, and tech teams to deliver their findings to users via systems and dashboards that guide Customer Service planning and policy rules. Key job responsibilities - Develop Causal, Economic, and Machine Learning models at scale. - Engage in economic analysis and raise the bar for research. - Inform strategic discussions with senior leaders across the company to guide policies. A day in the life If you are not sure that every qualification on the list above describes you exactly, we'd still love to hear from you! At Amazon, we value people with unique backgrounds, experiences, and skillsets. If you’re passionate about this role and want to make an impact on a global scale, please apply! Amazon offers a full range of benefits that support you and eligible family members, including domestic partners and their children. Benefits can vary by location, the number of regularly scheduled hours you work, length of employment, and job status such as seasonal or temporary employment. The benefits that generally apply to regular, full-time employees include: 1. Medical, Dental, and Vision Coverage 2. Maternity and Parental Leave Options 3. Paid Time Off (PTO) 4. 401(k) Plan About the team The Worldwide defect elimination team's mission is to understand and resolve all issues impacting customers at scale. The Customer Service Economics and Optimization team is a force multiplier within this group, helping to understand the impact of these issues and our actions to optimize the customer experience.