Skip to content

Blog

Transformer understanding

The transformer model was introduced in 2017 by Google's paper Attention Is All You Need.

Below image shows the architecture of the transformer model which is from the Google's paper Attention Is All You Need.

Python attrdict trap

AttrDict is an MIT-licensed library that provides mapping objects that allow their elements to be accessed both as keys and as attributes.

It's already not support the current python version now, for the lower version python, it's a useful library.

However, there is some magic behavior while using it.

Spring AOP

AOP stands for Aspect-Oriented Programming and it helps decouple cross-cutting concerns from the object that they affect. It’s similar to DI in the sense that DI helps decouple an application’s object from each other.

According to the Spring,

Spring event

From Spring Application Context introduction, we know one of the capability that ApplicationContext has, but `BeanFactory1 doesn't have is event publication.

ApplicationContext provides the event handling through the ApplicationEvent class and the ApplicationListener interface.

If a bean that implements the ApplicationListener interface is deployed into the context, every time an ApplicationEvent gets published to the ApplicationContext, that bean is notified. Essentially, this is the standard Observer design pattern.

Spring Application Context

What is ApplicationContext?

According to the Spring document,

The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory. It adds:

  • Easier integration with Spring’s AOP features

  • Message resource handling (for use in internationalization)

  • Event publication

  • Application-layer specific contexts such as the WebApplicationContext for use in web applications.

In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality. The ApplicationContext is a complete superset of the BeanFactory and is used exclusively in this chapter in descriptions of Spring’s IoC container.

Spring Bean Lifecycle

How Spring Manage Bean

ApplicationContext is an interface in Spring that provides configuration information to an application. It's the central interface in a Spring application. ApplicationContext is responsible for instantiating, configuring, and assembling beans. It reads configuration metadata to determine what objects to instantiate, configure, and assemble.

ApplicationContext provides basic features, including:

  • Publishing events to registered listeners

  • Methods for accessing application components

  • Internationalization support

  • Loading file resources

ApplicationContext is read-only while the application is running, but it can be reloaded if the implementation supports it. ApplicationContext is different from BeanFactory. BeanFactory creates a bean object when the getBean() method is called. ApplicationContext loads all the beans and creates objects at startup.

Spring Bean Scope

Spring Bean has four scopes,

  • singleton

    Singleton instance per Spring IoC container. This is the default.

  • prototype

    Scopes a single bean definition to any number of object instances. That means, every time, it requires to inject the bean or the getBean method is called.