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

US, VA, Arlington
The Sponsored Products and Brands team at Amazon Ads is re-imagining the advertising landscape through SOTA generative AI technologies, revolutionizing how millions of customers discover products and engage with brands across Amazon.com and beyond. We are at the forefront of re-inventing advertising experiences, bridging human creativity with artificial intelligence to transform every aspect of the advertising lifecycle from ad creation and optimization to performance analysis and customer insights. We are a passionate group of innovators dedicated to developing responsible and intelligent AI technologies that balance the needs of advertisers, enhance the shopping experience, and strengthen the marketplace. If you're energized by solving complex challenges and pushing the boundaries of what's possible with AI, join us in shaping the future of advertising. The Marketplace Intelligence (MI) team is looking for an Applied Science Manager to lead a team of scientists and engineers in building production ML and bandit solutions to customize the search experience. We determine which ads to show in Amazon search, where to place them, how many ads to place, and to which customers. This helps shoppers discover new products while helping advertisers put their products in front of the right customers, aligning shoppers’, advertisers’, and Amazon’s interests. To do this, we apply a broad range of machine learning, causal inference, and optimization techniques to continuously explore, learn, and optimize the allocation and ranking of ads on the search page. We are an interdisciplinary team with a focus on customer obsession and inventing and simplifying. Our primary focus is on improving the SP experience in search by gaining a deep understanding of shopper pain points and developing new innovative solutions to address them. You’ll lead the MI Interleaving team. The Interleaving team’s mission is to personalize and contextualize SP ad allocation on the search page. We do this by modeling shopper responses to the number, placement, and quality of ads. We use online experimentation, simulation, causal modeling, and online feedback to estimate the cost of displacing organic and sponsored content. Then, we incorporate those estimates into ad allocation to deliver an efficient and customized shopping experience for shoppers and improved discoverability and sales for advertisers. You’ll own the experimentation systems, models, and online model serving infrastructure to support these solutions. This is a unique opportunity for someone who wants to have broad business impact, a direct impact on customers and the search experience, build scaled real-time LLM and ML solutions, and lead a cross-functional team. If you are interested in machine learning, bandit learning, building production systems, and leading a team to build these solutions, this role is for you. We’re looking for a leader who can help lay out the vision for the team and grow with it. Key job responsibilities * Lead a team of scientists and engineers in building scalable machine learning solutions. * Develop a vision for contextualizing and personalizing SP ads in Amazon search. * Create, develop, and drive a data-driven product strategy to define the right quantitative measures of shopper impact, using this to evaluate decisions and opportunities. * Tackle and solve challenging science and business problems that balance the interests of advertisers, shoppers, and Amazon. * Own a portfolio of pragmatic long-term investments that drive long-term growth of the ads and retail businesses. * Develop real-time LLM and ML algorithms to allocate billions of ads per day in advertising auctions. * Develop efficient algorithms for multi-objective optimization and AI control methods to find operating points for the ad marketplace then evolve them * Develop scientists and ML engineers around machine learning, economics, and optimization for Advertising.
US, CA, Culver City
MULTIPLE POSITIONS AVAILABLE Employer: AMAZON.COM SERVICES LLC Offered Position: Data Scientist II Job Location: Culver City, California Job Number: AMZ10564056 Position Responsibilities: Design and implement scalable and reliable approaches to support or automate decision making throughout the business. Apply a range of data science techniques and tools combined with subject matter expertise to solve difficult business problems and cases in which the solution approach is unclear. Acquire data by building the necessary SQL / ETL queries. Import processes through various company specific interfaces for accessing Oracle, RedShift, and Spark storage systems. Build relationships with stakeholders and counterparts. Analyze data for trends and input validity by inspecting univariate distributions, exploring bivariate relationships, constructing appropriate transformations, and tracking down the source and meaning of anomalies. Build models using statistical modeling, mathematical modeling, econometric modeling, network modeling, social network modeling, natural language processing, machine learning algorithms, genetic algorithms, and neural networks. Validate models against alternative approaches, expected and observed outcome, and other business defined key performance indicators. Implement models that comply with evaluations of the computational demands, accuracy, and reliability of the relevant ETL processes at various stages of production. 40 hours / week, 8:00am-5:00pm, Salary Range: $158,681/year to $184,000/year. Amazon is a total compensation company. Dependent on the position offered, equity, sign-on payments, and other forms of compensation may be provided as part of a total compensation package, in addition to a full range of medical, financial, and/or other benefits. For more information, visit: https://www.aboutamazon.com/workplace/employee-benefits. Amazon.com is an Equal Opportunity-Affirmative Action Employer – Minority / Female / Disability / Veteran / Gender Identity / Sexual Orientation.#0000
ES, M, Madrid
At Amazon, we are committed to being the Earth’s most customer-centric company. The European International Technology group (EU INTech) owns the enhancement and delivery of Amazon’s engineering to all the varied customers and cultures of the world. We do this through a combination of partnerships with other Amazon technical teams and our own innovative new projects. You will be joining the Tools and Machine Learning (Tamale) team. As part of EU INTech, we tackle complex, high-impact problems at the intersection of e-commerce, AI, and customer experience; going well beyond traditional ML pipelines. Our work spans multiple frontiers: we build GenAI-powered data solutions, enabling scalable and cost-efficient training data generation at Amazon scale. We design and deploy agentic systems for detecting and fixing quality issues across Amazon's retail surfaces. And we develop ranking and recommendation models for Haul shopping experiences. We are looking for a passionate, talented, and inventive Scientist with a strong machine learning background to help build industry-leading machine learning solutions. We strongly value your hard work and obsession to solve complex problems on behalf of Amazon customers. Key job responsibilities We look for applied scientists who possess a wide variety of skills. As the successful applicant for this role, you will with work closely with your business partners to identify opportunities for innovation. You will apply machine learning solutions to automate manual processes, to scale existing systems and to improve catalog data quality, to name just a few. You will work with business leaders, scientists, and product managers to translate business and functional requirements into concrete deliverables, including the design, development, testing, and deployment of highly scalable distributed services. You will be part of team of scientists and engineers working on solving data quality issues at scale. You will be able to influence the scientific roadmap of the team, setting the standards for scientific excellence. You will be working with state-of-the-art models, including image to text, Multimodal LLMs and GenAI. Your work will improve the experience of millions of daily customers using Amazon in Europe and in other regions. You will have the chance to have great customer impact and continue growing in one of the most innovative companies in the world. You will learn a huge amount - and have a lot of fun - in the process!
CH, Zurich
RIVR, an Amazon company, is building Physical AI by deploying autonomous robots for real-world doorstep delivery. Operating daily in diverse urban environments, RIVR's robots continuously learn from and navigate the millions of scenarios encountered during deliveries. By owning the full stack from software. Our fleet of delivery robots operates globally today, generating vast amounts of robotic real-world data. By utilizing state-of-the-art Vision-Language-Action (VLA) models, large-scale generalist models (like Transformers), generative AI, and similar methods, we can leverage this pool of data to significantly enhance its autonomy, navigation, and manipulation skills. In this role, you will develop multi-modal models that enable robots to autonomously generate actions from demonstrations, real-time sensor data, and natural language commands. We are seeking an expert in VLA models, imitation learning, and generative AI techniques with a deep knowledge of supervised, and self-supervised learning algorithms. If you are passionate about pushing the boundaries of AI we invite you to join us in shaping the future of intelligent robotics. Key job responsibilities Develop and implement Vision-Language-Action (VLA) models, generalist robot transformers, and imitation learning algorithms (e.g., diffusion policies) to enable robots to autonomously execute complex tasks. Design, test, and refine your algorithms to meet the demands of complex real-world autonomy and navigation tasks, with a focus on spatial reasoning and generalization. Streamline the data collection and training workflow to efficiently expand model capabilities with new tasks and data sources. Collaborate with the reinforcement learning team to innovate methods that leverage both simulated and real-world data. Optimize and distill networks for real-time deployment on the edge (e.g. Nvidia Jetson Thor). Build, lead and mentor an exceptional team of software engineers. Provide expert guidance to product managers and executives for strategic decision-making. Create and maintain documentation, guidelines, and best practices to streamline knowledge sharing.
CL, Virtual
The Central Science Team within Amazon’s People Experience and Technology org (PXTCS) uses economics, behavioral science, statistics, and machine learning to proactively identify mechanisms and process improvements which simultaneously improve Amazon and the lives, well-being, and the value of work to Amazonians. We are an interdisciplinary team, which combines the talents of science and engineering to develop and deliver solutions that measurably achieve this goal. We are looking for a Economist II who is able to provide structure around complex business problems, hone those complex problems into specific, scientific questions, and test those questions to generate insights. The ideal candidate will work with various science, engineering, operations, and analytics teams to estimate models and algorithms on large scale data, design pilots and measure their impact, and transform successful prototypes into improved policies and programs at scale. They will lead teams of researchers to produce robust, objective research results and insights which can be communicated to a broad audience inside and outside of Amazon. The ideal candidate has a PhD in Economics and deep expertise in causal inference and applied econometrics. Experience with large-scale data, proficiency in statistical programming (Python), and familiarity with machine learning methods are a plus. To be successful in this role, you should be comfortable operating with ambiguity, able to independently scope and prioritize research agendas, skilled at influencing decisions through rigorous analysis, and comfortable with using AI tools.
US, MA, Boston
Our team is involved with pre-silicon design verification for custom IP. A critical requirement of the verification flow is the requirement of legal and realistic stimulus of a custom Machine Learning Accelerator Chip. Content creation is built using formal methods that model legal behavior of the design and then solving the problem to create the specific assembly tests. The entire frame work for creating these custom tests is developed using a SMT solver and custom software code to guide the solution space into templated scenarios. This highly visible and innovative role requires the design of this solving framework and collaborating with design verification engineers, hardware architects and designers to ensure that interesting content can be created for the projects needs. Key job responsibilities Develop an understanding for a custom machine learning instruction set architecture. Model correctness of instruction streams using first order logic. Create custom API's to allow control over scheduling and randomness. Deploy algorithms to ensure concurrent code is safely constructed. Create coverage metrics to ensure solution space coverage. Use novel methods like machine learning to automate content creation. About the team Utility Computing (UC) 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 customers who require specialized security solutions for their cloud services. Annapurna Labs (our organization within AWS UC) designs silicon and software that accelerates innovation. Customers choose us to create cloud solutions that solve challenges that were unimaginable a short time ago—even yesterday. Our custom chips, accelerators, and software stacks enable us to take on technical challenges that have never been seen before, and deliver results that help our customers change the world.
IN, KA, Bengaluru
Have you ever wondered how that Amazon box with the smile arrives so quickly, where it came from, and how much it cost Amazon to deliver? The WW Amazon Logistics, Business Analytics team manages the delivery of tens of millions of products every week to Amazon's customers, achieving on-time delivery in a cost-effective manner. We are seeking an enthusiastic, customer-obsessed Research Science Manager(RSM) with strong analytical skills to join our team. This role is crucial in optimizing Amazon's vast delivery network and will have significant impact on the customer experience, particularly in the final phase of delivery. As a Research Science Manager, you will: 1. Address business challenges through building compelling cases and using data to influence change across the organization 2. Develop input and assumptions based on preexisting models to estimate costs and savings opportunities associated with varying levels of network growth and operations 3. Create metrics to measure business performance, identify root causes and trends, and prescribe action plans 4. Manage multiple high-impact projects simultaneously 5. Work with technology teams and product managers to develop new tools and systems supporting business growth 6. Communicate with and support various internal stakeholders and external audiences 7. Implement scheduling solutions, improve metrics, and develop scalable processes and tools Looking for minds with: Extensive experience in operations research and data-driven decision making Strong analytical and problem-solving skills Robust program management and research science skills Ability to work with a team and make independent decisions in ambiguous environments Customer-obsessed mindset with a focus on improving the Amazon delivery experience This role offers the autonomy to think strategically and make data-driven decisions from day one. Join us in shaping the future of e-commerce delivery and addressing the core challenges in our world-class operations space! Key job responsibilities Key job responsibilities 1. Advanced Modeling and Algorithm Development: Design and implement sophisticated machine learning models for logistics optimization Develop complex time series forecasting algorithms for demand prediction and resource allocation 2. AI and Machine Learning Integration: Architect and deploy AI-powered systems to enhance decision-making in logistics operations Implement deep learning techniques for image recognition in package sorting and handling Develop reinforcement learning algorithms for adaptive scheduling and resource management 3. Big Data Analytics and Processing: Design and implement distributed computing solutions for processing massive logistics datasets Utilize cloud computing platforms (e.g., AWS) for scalable data processing and analysis 4. AI-Driven Workflow Optimization: Design and implement AI agents for autonomous decision-making in logistics processes Create machine learning models for customer behavior analysis and personalized delivery options 5. Software Development and System Architecture: Write efficient, scalable code in languages such as Python, Java, or C++ Develop and maintain complex software systems for logistics optimization Stay at the forefront of AI and ML research Publish research findings in top-tier conferences and journals About the team We are Amazon's Last Mile Science and Analytics team, dedicated to improving e-commerce delivery. We work to optimize our vast network, forecast demand using machine learning, and enhance route efficiency. Our efforts focus on developing innovative delivery methods, applying AI to solve complex problems, and conducting geospatial analysis. We create simulations to refine processes and plan capacity effectively. Operating globally, we strive to develop adaptable solutions for diverse markets. We aim to advance logistics science, continually improving speed, efficiency, and customer satisfaction, in support of Amazon's mission to be Earth's most customer-centric company.
IN, KA, Bengaluru
Amazon Devices is an inventive research and development company that designs and engineer high-profile devices like the Kindle family of products, Fire Tablets, Fire TV, Health Wellness, Amazon Echo & Astro products. This is an exciting opportunity to join Amazon in developing state-of-the-art techniques that bring Gen AI on edge for our consumer products. We are looking for exceptional scientists to join our Applied Science team and help develop the next generation of edge models, and optimize them while doing co-designed with custom ML HW based on a revolutionary architecture. Work hard. Have Fun. Make History. Key job responsibilities - Quantize, prune, distill, finetune Gen AI models to optimize for edge platforms - Fundamentally understand Amazon’s underlying Neural Edge Engine to invent optimization techniques - Analyze deep learning workloads and provide guidance to map them to Amazon’s Neural Edge Engine - Use first principles of Information Theory, Scientific Computing, Deep Learning Theory, Non Equilibrium Thermodynamics - Train custom Gen AI models that beat SOTA and paves path for developing production models - Collaborate closely with compiler engineers, fellow Applied Scientists, Hardware Architects and product teams to build the best ML-centric solutions for our devices - Publish in open source and present on Amazon's behalf at key ML conferences - NeurIPS, ICLR, MLSys.
US, CA, Culver City
MULTIPLE POSITIONS AVAILABLE Employer: AMAZON.COM SERVICES LLC Offered Position: Applied Scientist III Job Location: Culver City, California Job Number: AMZ10564141 Position Responsibilities: Participate in the design, development, evaluation, deployment and updating of data-driven models and analytical solutions for machine learning (ML) and/or natural language (NL) applications. Develop and/or apply statistical modeling techniques (e.g. Bayesian models and deep neural networks), optimization methods, and other ML techniques to different applications in business and engineering. Routinely build and deploy ML models on available data, and run and analyze experiments in a production environment. Identify new opportunities for research in order to meet business goals. Research and implement novel ML and statistical approaches to add value to the business. Mentor junior engineers and scientists. 40 hours / week, 8:00am-5:00pm, Salary Range: $167,100/year to $226,100/year. Amazon is a total compensation company. Dependent on the position offered, equity, sign-on payments, and other forms of compensation may be provided as part of a total compensation package, in addition to a full range of medical, financial, and/or other benefits. For more information, visit: https://www.aboutamazon.com/workplace/employee-benefits. Amazon.com is an Equal Opportunity-Affirmative Action Employer – Minority / Female / Disability / Veteran / Gender Identity / Sexual Orientation.#0000
IN, KA, Bengaluru
We are looking for a talented Applied Scientist to join our team. In this role, you will design, develop, and deploy machine learning and computer vision models that solve real-world problems at scale in the Amazon grocery domain. You will work closely with engineering, product, and business teams to turn complex technical challenges into production-ready solutions, and own the model development lifecycle from experimentation through deployment. You will bring scientific rigor to every stage — from data analysis and model design to evaluation and iteration. This is a high-impact role where your models will directly improve the shopping experience for millions of customers in Amazon grocery stores. Key job responsibilities Design, train, and evaluate computer vision and machine learning models for complex grocery-domain problems including product identification, shelf perception, and in-store scene understanding — iterating rapidly from prototype to production-quality solutions Conduct rigorous exploratory data analysis to characterize domain-specific challenges (image variability, catalog gaps, label noise) and translate findings into actionable modeling decisions Own the model development lifecycle from experimentation through deployment — collaborating with software and ML engineers to ensure models meet latency, throughput, and reliability requirements at production scale Design and execute offline and online evaluation frameworks — defining metrics that capture both model performance and downstream business impact, and diagnosing failure modes to prioritize improvements Build and improve data pipelines and annotation workflows that feed model training, including active learning strategies to maximize label efficiency Communicate technical results, trade-offs, and recommendations clearly to engineering, product, and business stakeholders — connecting model behavior to customer experience outcomes Stay current with state-of-the-art research in computer vision, multimodal learning, and representation learning — evaluating and adapting promising techniques to team-specific problems Contribute to a culture of scientific rigor through reproducible experimentation, thorough documentation, peer code and design reviews, and raising the quality bar for the team A day in the life As an Applied Scientist on the GRAISE team, you'll spend your days analyzing model performance from overnight experiments, collaborating with engineers to deploy computer vision models to production, and prototyping new approaches using multimodal learning with store video and sensor data. You'll present findings to product and business stakeholders, translating technical results into actionable recommendations. Throughout the day, you'll balance rigorous scientific thinking with practical engineering constraints, knowing your work directly improves the shopping experience for millions of customers in Amazon grocery stores. About the team The GRAISE team (Grocery, Retail & In-Store Experience) within World Wide Grocery Store Tech (WWGST) builds foundational AI and machine learning systems that power Amazon's in-store grocery technologies. We develop domain-specific models that solve uniquely complex challenges in grocery — from smart shopping carts and inventory intelligence to personalization and store operations. Our mission is to create technology which makes grocery shopping more convenient, economical, personalized, and enjoyable for customers while empowering retailers with operational efficiency