initial commit
Browse files- Dockerfile +11 -0
- app.py +138 -0
- chainlit.md +5 -0
- docs/bh.txt +291 -0
- docs/bh2.txt +25 -0
- docs/bh3.txt +40 -0
- requirements.txt +11 -0
- utils/__pycache__/text_utils.cpython-311.pyc +0 -0
- utils/__pycache__/vectordatabase.cpython-311.pyc +0 -0
- utils/openai_utils/.DS_Store +0 -0
- utils/openai_utils/__init__.py +0 -0
- utils/openai_utils/__pycache__/__init__.cpython-311.pyc +0 -0
- utils/openai_utils/__pycache__/chatmodel.cpython-311.pyc +0 -0
- utils/openai_utils/__pycache__/embedding.cpython-311.pyc +0 -0
- utils/openai_utils/__pycache__/prompts.cpython-311.pyc +0 -0
- utils/openai_utils/chatmodel.py +27 -0
- utils/openai_utils/embedding.py +52 -0
- utils/openai_utils/prompts.py +75 -0
- utils/text_utils.py +77 -0
- utils/vectordatabase.py +81 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
RUN useradd -m -u 1000 user
|
3 |
+
USER user
|
4 |
+
ENV HOME=/home/user \
|
5 |
+
PATH=/home/user/.local/bin:$PATH
|
6 |
+
WORKDIR $HOME/app
|
7 |
+
COPY --chown=user . $HOME/app
|
8 |
+
COPY ./requirements.txt ~/app/requirements.txt
|
9 |
+
RUN pip install -r requirements.txt
|
10 |
+
COPY . .
|
11 |
+
CMD ["chainlit", "run", "app.py", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
|
3 |
+
import chainlit as cl #importing chainlit for our app
|
4 |
+
from chainlit.input_widget import Select, Switch, Slider #importing chainlit settings selection tools
|
5 |
+
from chainlit.prompt import Prompt, PromptMessage #importing prompt tools
|
6 |
+
from chainlit.playground.providers import ChatOpenAI #importing ChatOpenAI tools
|
7 |
+
|
8 |
+
import datetime
|
9 |
+
|
10 |
+
# import nest_asyncio
|
11 |
+
# nest_asyncio.apply()
|
12 |
+
|
13 |
+
import openai
|
14 |
+
import os
|
15 |
+
|
16 |
+
from utils.text_utils import TextFileLoader, CharacterTextSplitter
|
17 |
+
from utils.vectordatabase import VectorDatabase
|
18 |
+
|
19 |
+
from utils.openai_utils.prompts import (
|
20 |
+
UserRolePrompt,
|
21 |
+
SystemRolePrompt,
|
22 |
+
AssistantRolePrompt,
|
23 |
+
)
|
24 |
+
|
25 |
+
from utils.openai_utils.chatmodel import ChatOpenAI
|
26 |
+
|
27 |
+
import wandb
|
28 |
+
from wandb.sdk.data_types.trace_tree import Trace
|
29 |
+
|
30 |
+
RAQA_PROMPT_TEMPLATE = """
|
31 |
+
Use the provided context to answer the user's query.
|
32 |
+
|
33 |
+
You may not answer the user's query unless there is specific context in the following text.
|
34 |
+
|
35 |
+
If you do not know the answer, or cannot answer, please respond with "I don't know".
|
36 |
+
|
37 |
+
Context:
|
38 |
+
{context}
|
39 |
+
"""
|
40 |
+
|
41 |
+
raqa_prompt = SystemRolePrompt(RAQA_PROMPT_TEMPLATE)
|
42 |
+
|
43 |
+
USER_PROMPT_TEMPLATE = """
|
44 |
+
User Query:
|
45 |
+
{user_query}
|
46 |
+
"""
|
47 |
+
|
48 |
+
user_prompt = UserRolePrompt(USER_PROMPT_TEMPLATE)
|
49 |
+
|
50 |
+
# You only need the api key inserted here if it's not in your .env file
|
51 |
+
openai.api_key = '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'
|
52 |
+
wandb_key = '32ba71217e4c267962cf2e5603326490019df26a'
|
53 |
+
|
54 |
+
os.environ["OPENAI_API_KEY"] = openai.api_key
|
55 |
+
os.environ["WANDB_API_KEY"] = wandb_key
|
56 |
+
# os.environ["WANDB_DIR"] = './wandb/'
|
57 |
+
|
58 |
+
text_loader = TextFileLoader('docs/')
|
59 |
+
documents = text_loader.load_documents()
|
60 |
+
|
61 |
+
text_splitter = CharacterTextSplitter()
|
62 |
+
split_documents = text_splitter.split_texts(documents)
|
63 |
+
|
64 |
+
vector_db = VectorDatabase()
|
65 |
+
vector_db = asyncio.run(vector_db.abuild_from_list(split_documents))
|
66 |
+
|
67 |
+
wandb_project = 'raqa_visibility'
|
68 |
+
wandb.init(project=wandb_project)
|
69 |
+
|
70 |
+
chat_openai = ChatOpenAI()
|
71 |
+
|
72 |
+
class RetrievalAugmentedQAPipeline:
|
73 |
+
def __init__(self, llm: ChatOpenAI(), vector_db_retriever: VectorDatabase, wandb_project = None) -> None:
|
74 |
+
self.llm = llm
|
75 |
+
self.vector_db_retriever = vector_db_retriever
|
76 |
+
self.wandb_project = wandb_project
|
77 |
+
|
78 |
+
def run_pipeline(self, user_query: str) -> str:
|
79 |
+
context_list = self.vector_db_retriever.search_by_text(user_query, k=4)
|
80 |
+
|
81 |
+
context_prompt = ""
|
82 |
+
for context in context_list:
|
83 |
+
context_prompt += context[0] + "\n"
|
84 |
+
|
85 |
+
formatted_system_prompt = raqa_prompt.create_message(context=context_prompt)
|
86 |
+
|
87 |
+
formatted_user_prompt = user_prompt.create_message(user_query=user_query)
|
88 |
+
|
89 |
+
start_time = datetime.datetime.now().timestamp() * 1000
|
90 |
+
|
91 |
+
try:
|
92 |
+
openai_response = self.llm.run([formatted_system_prompt, formatted_user_prompt], text_only=False)
|
93 |
+
end_time = datetime.datetime.now().timestamp() * 1000
|
94 |
+
status = "success"
|
95 |
+
status_message = (None, )
|
96 |
+
response_text = openai_response.choices[0].message.content
|
97 |
+
token_usage = openai_response["usage"].to_dict()
|
98 |
+
model = openai_response["model"]
|
99 |
+
|
100 |
+
except Exception as e:
|
101 |
+
end_time = datetime.datetime.now().timestamp() * 1000
|
102 |
+
status = "error"
|
103 |
+
status_message = str(e)
|
104 |
+
response_text = ""
|
105 |
+
token_usage = {}
|
106 |
+
model = ""
|
107 |
+
|
108 |
+
if self.wandb_project:
|
109 |
+
root_span = Trace(
|
110 |
+
name="root_span",
|
111 |
+
kind="llm",
|
112 |
+
status_code=status,
|
113 |
+
status_message=status_message,
|
114 |
+
start_time_ms=start_time,
|
115 |
+
end_time_ms=end_time,
|
116 |
+
metadata={
|
117 |
+
"token_usage" : token_usage,
|
118 |
+
"model_name" : model
|
119 |
+
},
|
120 |
+
inputs= {"system_prompt" : formatted_system_prompt, "user_prompt" : formatted_user_prompt},
|
121 |
+
outputs= {"response" : response_text}
|
122 |
+
)
|
123 |
+
|
124 |
+
root_span.log(name="openai_trace")
|
125 |
+
|
126 |
+
return response_text if response_text else "We ran into an error. Please try again later. Full Error Message: " + status_message
|
127 |
+
|
128 |
+
@cl.on_chat_start # marks a function that will be executed at the start of a user session
|
129 |
+
async def start_chat():
|
130 |
+
retrieval_augmented_qa_pipeline = RetrievalAugmentedQAPipeline(vector_db_retriever=vector_db, llm=chat_openai, wandb_project=wandb_project)
|
131 |
+
cl.user_session.set("pipeline", retrieval_augmented_qa_pipeline)
|
132 |
+
|
133 |
+
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
134 |
+
async def main(message: str):
|
135 |
+
retrieval_augmented_qa_pipeline = cl.user_session.get("pipeline")
|
136 |
+
completion = retrieval_augmented_qa_pipeline.run_pipeline(message)
|
137 |
+
|
138 |
+
await cl.Message(content=completion).send()
|
chainlit.md
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Retrieval Augmented QA !
|
2 |
+
|
3 |
+
This example shows the power of Retrieval Augmented QA using a Vector database. More specifically, we first load source documents about black holes and subsequently chunk them and send each of those chunks to the text-embedding-ada-002 OpenAI API endpoint. Next, we define a Vector batabase locally to store the text/vector representations for the chunks as key/value pairs. Using custom role prompts, we force the LLM to reply "I don't know." when it does not have enough context about an user query. However, in case the query is about black holes, the LLM gets relevant passages from the source documents and returns them.
|
4 |
+
|
5 |
+
|
docs/bh.txt
ADDED
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A black hole is a region of spacetime where gravity is so strong that nothing, including light or other electromagnetic waves, has enough energy to escape it. The theory of general relativity predicts that a sufficiently compact mass can deform spacetime to form a black hole. The boundary of no escape is called the event horizon. Although it has a great effect on the fate and circumstances of an object crossing it, it has no locally detectable features according to general relativity. In many ways, a black hole acts like an ideal black body, as it reflects no light. Moreover, quantum field theory in curved spacetime predicts that event horizons emit Hawking radiation, with the same spectrum as a black body of a temperature inversely proportional to its mass. This temperature is of the order of billionths of a kelvin for stellar black holes, making it essentially impossible to observe directly.
|
2 |
+
|
3 |
+
Objects whose gravitational fields are too strong for light to escape were first considered in the 18th century by John Michell and Pierre-Simon Laplace. In 1916, Karl Schwarzschild found the first modern solution of general relativity that would characterize a black hole. David Finkelstein, in 1958, first published the interpretation of "black hole" as a region of space from which nothing can escape. Black holes were long considered a mathematical curiosity; it was not until the 1960s that theoretical work showed they were a generic prediction of general relativity. The discovery of neutron stars by Jocelyn Bell Burnell in 1967 sparked interest in gravitationally collapsed compact objects as a possible astrophysical reality. The first black hole known was Cygnus X-1, identified by several researchers independently in 1971.
|
4 |
+
|
5 |
+
Black holes of stellar mass form when massive stars collapse at the end of their life cycle. After a black hole has formed, it can grow by absorbing mass from its surroundings. Supermassive black holes of millions of solar masses (M☉) may form by absorbing other stars and merging with other black holes. There is consensus that supermassive black holes exist in the centres of most galaxies.
|
6 |
+
|
7 |
+
The presence of a black hole can be inferred through its interaction with other matter and with electromagnetic radiation such as visible light. Any matter that falls onto a black hole can form an external accretion disk heated by friction, forming quasars, some of the brightest objects in the universe. Stars passing too close to a supermassive black hole can be shredded into streamers that shine very brightly before being "swallowed." If other stars are orbiting a black hole, their orbits can be used to determine the black hole's mass and location. Such observations can be used to exclude possible alternatives such as neutron stars. In this way, astronomers have identified numerous stellar black hole candidates in binary systems and established that the radio source known as Sagittarius A*, at the core of the Milky Way galaxy, contains a supermassive black hole of about 4.3 million solar masses.
|
8 |
+
|
9 |
+
History
|
10 |
+
Simulated view of a black hole in front of the Large Magellanic Cloud. Note the gravitational lensing effect, which produces two enlarged but highly distorted views of the Cloud. Across the top, the Milky Way disk appears distorted into an arc. Published in 2019.
|
11 |
+
|
12 |
+
The idea of a body so big that even light could not escape was briefly proposed by English astronomical pioneer and clergyman John Michell in a letter published in November 1784. Michell's simplistic calculations assumed such a body might have the same density as the Sun, and concluded that one would form when a star's diameter exceeds the Sun's by a factor of 500, and its surface escape velocity exceeds the usual speed of light. Michell referred to these bodies as dark stars. He correctly noted that such supermassive but non-radiating bodies might be detectable through their gravitational effects on nearby visible bodies. Scholars of the time were initially excited by the proposal that giant but invisible 'dark stars' might be hiding in plain view, but enthusiasm dampened when the wavelike nature of light became apparent in the early nineteenth century, as if light were a wave rather than a particle, it was unclear what, if any, influence gravity would have on escaping light waves.
|
13 |
+
|
14 |
+
Modern physics discredits Michell's notion of a light ray shooting directly from the surface of a supermassive star, being slowed down by the star's gravity, stopping, and then free-falling back to the star's surface.
|
15 |
+
|
16 |
+
In 1915, Albert Einstein developed his theory of general relativity, having earlier shown that gravity does influence light's motion. Only a few months later, Karl Schwarzschild found a solution to the Einstein field equations that describes the gravitational field of a point mass and a spherical mass. A few months after Schwarzschild, Johannes Droste, a student of Hendrik Lorentz, independently gave the same solution for the point mass and wrote more extensively about its properties. This solution had a peculiar behaviour at what is now called the Schwarzschild radius, where it became singular, meaning that some of the terms in the Einstein equations became infinite. The nature of this surface was not quite understood at the time.
|
17 |
+
|
18 |
+
In 1924, Arthur Eddington showed that the singularity disappeared after a change of coordinates, although it took until 1933 for Georges Lemaître to realize that this meant the singularity at the Schwarzschild radius was a non-physical coordinate singularity. Arthur Eddington did however comment on the possibility of a star with mass compressed to the Schwarzschild radius in a 1926 book, noting that Einstein's theory allows us to rule out overly large densities for visible stars like Betelgeuse because "a star of 250 million km radius could not possibly have so high a density as the Sun. Firstly, the force of gravitation would be so great that light would be unable to escape from it, the rays falling back to the star like a stone to the earth. Secondly, the red shift of the spectral lines would be so great that the spectrum would be shifted out of existence. Thirdly, the mass would produce so much curvature of the spacetime metric that space would close up around the star, leaving us outside (i.e., nowhere)."
|
19 |
+
|
20 |
+
In 1931, Subrahmanyan Chandrasekhar calculated, using special relativity, that a non-rotating body of electron-degenerate matter above a certain limiting mass (now called the Chandrasekhar limit at 1.4 M☉) has no stable solutions. His arguments were opposed by many of his contemporaries like Eddington and Lev Landau, who argued that some yet unknown mechanism would stop the collapse.[26] They were partly correct: a white dwarf slightly more massive than the Chandrasekhar limit will collapse into a neutron star, which is itself stable. But in 1939, Robert Oppenheimer and others predicted that neutron stars above another limit (the Tolman–Oppenheimer–Volkoff limit) would collapse further for the reasons presented by Chandrasekhar, and concluded that no law of physics was likely to intervene and stop at least some stars from collapsing to black holes. Their original calculations, based on the Pauli exclusion principle, gave it as 0.7 M☉; subsequent consideration of neutron-neutron repulsion mediated by the strong force raised the estimate to approximately 1.5 M☉ to 3.0 M☉. Observations of the neutron star merger GW170817, which is thought to have generated a black hole shortly afterward, have refined the TOV limit estimate to ~2.17 M☉. Oppenheimer and his co-authors interpreted the singularity at the boundary of the Schwarzschild radius as indicating that this was the boundary of a bubble in which time stopped. This is a valid point of view for external observers, but not for infalling observers. Because of this property, the collapsed stars were called "frozen stars", because an outside observer would see the surface of the star frozen in time at the instant where its collapse takes it to the Schwarzschild radius.
|
21 |
+
|
22 |
+
Also in 1939, Einstein would attempt to prove that black holes were impossible in his publication "On a Stationary System with Spherical Symmetry Consisting of Many Gravitating Masses", using his theory of general relativity to defend his argument. Months later, Oppenheimer and his student Hartland Snyder would provide the Oppenheimer–Snyder model in their paper "On Continued Gravitational Contraction", which predicted the existence of black holes. In the paper, which made no reference to Einstein's recent publication, Oppenheimer and Snyder used Einstein's own theory of general relativity to show the conditions on how a black hole could develop for the first time in contemporary physics .
|
23 |
+
Golden age
|
24 |
+
|
25 |
+
In 1958, David Finkelstein identified the Schwarzschild surface as an event horizon, "a perfect unidirectional membrane: causal influences can cross it in only one direction". This did not strictly contradict Oppenheimer's results, but extended them to include the point of view of in falling observers. Finkelstein's solution extended the Schwarzschild solution for the future of observers falling into a black hole. A complete extension had already been found by Martin Kruskal, who was urged to publish it.[39]
|
26 |
+
|
27 |
+
These results came at the beginning of the golden age of general relativity, which was marked by general relativity and black holes becoming mainstream subjects of research. This process was helped by the discovery of pulsars by Jocelyn Bell Burnell in 1967,[40][41] which, by 1969, were shown to be rapidly rotating neutron stars.[42] Until that time, neutron stars, like black holes, were regarded as just theoretical curiosities; but the discovery of pulsars showed their physical relevance and spurred a further interest in all types of compact objects that might be formed by gravitational collapse.[citation needed]
|
28 |
+
|
29 |
+
In this period more general black hole solutions were found. In 1963, Roy Kerr found the exact solution for a rotating black hole. Two years later, Ezra Newman found the axisymmetric solution for a black hole that is both rotating and electrically charged.[43] Through the work of Werner Israel,[44] Brandon Carter,[45][46] and David Robinson[47] the no-hair theorem emerged, stating that a stationary black hole solution is completely described by the three parameters of the Kerr–Newman metric: mass, angular momentum, and electric charge.[48]
|
30 |
+
|
31 |
+
At first, it was suspected that the strange features of the black hole solutions were pathological artifacts from the symmetry conditions imposed, and that the singularities would not appear in generic situations. This view was held in particular by Vladimir Belinsky, Isaak Khalatnikov, and Evgeny Lifshitz, who tried to prove that no singularities appear in generic solutions. However, in the late 1960s Roger Penrose[49] and Stephen Hawking used global techniques to prove that singularities appear generically.[50] For this work, Penrose received half of the 2020 Nobel Prize in Physics, Hawking having died in 2018.[51] Based on observations in Greenwich and Toronto in the early 1970s, Cygnus X-1, a galactic X-ray source discovered in 1964, became the first astronomical object commonly accepted to be a black hole.[52][53]
|
32 |
+
|
33 |
+
Work by James Bardeen, Jacob Bekenstein, Carter, and Hawking in the early 1970s led to the formulation of black hole thermodynamics.[54] These laws describe the behaviour of a black hole in close analogy to the laws of thermodynamics by relating mass to energy, area to entropy, and surface gravity to temperature. The analogy was completed when Hawking, in 1974, showed that quantum field theory implies that black holes should radiate like a black body with a temperature proportional to the surface gravity of the black hole, predicting the effect now known as Hawking radiation.[55]
|
34 |
+
Observation
|
35 |
+
|
36 |
+
On 11 February 2016, the LIGO Scientific Collaboration and the Virgo collaboration announced the first direct detection of gravitational waves, representing the first observation of a black hole merger.[56] On 10 April 2019, the first direct image of a black hole and its vicinity was published, following observations made by the Event Horizon Telescope (EHT) in 2017 of the supermassive black hole in Messier 87's galactic centre.[57][58][59] As of 2023, the nearest known body thought to be a black hole, Gaia BH1, is around 1,560 light-years (480 parsecs) away.[60] Though only a couple dozen black holes have been found so far in the Milky Way, there are thought to be hundreds of millions, most of which are solitary and do not cause emission of radiation.[61] Therefore, they would only be detectable by gravitational lensing.
|
37 |
+
Etymology
|
38 |
+
|
39 |
+
John Michell used the term "dark star" in a November 1783 letter to Henry Cavendish,[62] and in the early 20th century, physicists used the term "gravitationally collapsed object". Science writer Marcia Bartusiak traces the term "black hole" to physicist Robert H. Dicke, who in the early 1960s reportedly compared the phenomenon to the Black Hole of Calcutta, notorious as a prison where people entered but never left alive.[63]
|
40 |
+
|
41 |
+
The term "black hole" was used in print by Life and Science News magazines in 1963,[63] and by science journalist Ann Ewing in her article "'Black Holes' in Space", dated 18 January 1964, which was a report on a meeting of the American Association for the Advancement of Science held in Cleveland, Ohio.[64][65]
|
42 |
+
|
43 |
+
In December 1967, a student reportedly suggested the phrase "black hole" at a lecture by John Wheeler;[64] Wheeler adopted the term for its brevity and "advertising value", and it quickly caught on,[66] leading some to credit Wheeler with coining the phrase.[67]
|
44 |
+
Properties and structure
|
45 |
+
Simple illustration of a non-spinning black hole
|
46 |
+
Artistic depiction of a black hole and its features
|
47 |
+
|
48 |
+
The no-hair theorem postulates that, once it achieves a stable condition after formation, a black hole has only three independent physical properties: mass, electric charge, and angular momentum; the black hole is otherwise featureless. If the conjecture is true, any two black holes that share the same values for these properties, or parameters, are indistinguishable from one another. The degree to which the conjecture is true for real black holes under the laws of modern physics is currently an unsolved problem.[48]
|
49 |
+
|
50 |
+
These properties are special because they are visible from outside a black hole. For example, a charged black hole repels other like charges just like any other charged object. Similarly, the total mass inside a sphere containing a black hole can be found by using the gravitational analog of Gauss's law (through the ADM mass), far away from the black hole.[68] Likewise, the angular momentum (or spin) can be measured from far away using frame dragging by the gravitomagnetic field, through for example the Lense–Thirring effect.[69]
|
51 |
+
|
52 |
+
When an object falls into a black hole, any information about the shape of the object or distribution of charge on it is evenly distributed along the horizon of the black hole, and is lost to outside observers. The behavior of the horizon in this situation is a dissipative system that is closely analogous to that of a conductive stretchy membrane with friction and electrical resistance—the membrane paradigm.[70] This is different from other field theories such as electromagnetism, which do not have any friction or resistivity at the microscopic level, because they are time-reversible. Because a black hole eventually achieves a stable state with only three parameters, there is no way to avoid losing information about the initial conditions: the gravitational and electric fields of a black hole give very little information about what went in. The information that is lost includes every quantity that cannot be measured far away from the black hole horizon, including approximately conserved quantum numbers such as the total baryon number and lepton number. This behavior is so puzzling that it has been called the black hole information loss paradox.[71][72]
|
53 |
+
Gravitational time dilation around a black hole
|
54 |
+
Physical properties
|
55 |
+
|
56 |
+
The simplest static black holes have mass but neither electric charge nor angular momentum. These black holes are often referred to as Schwarzschild black holes after Karl Schwarzschild who discovered this solution in 1916.[19] According to Birkhoff's theorem, it is the only vacuum solution that is spherically symmetric.[73] This means there is no observable difference at a distance between the gravitational field of such a black hole and that of any other spherical object of the same mass. The popular notion of a black hole "sucking in everything" in its surroundings is therefore correct only near a black hole's horizon; far away, the external gravitational field is identical to that of any other body of the same mass.[74]
|
57 |
+
|
58 |
+
Solutions describing more general black holes also exist. Non-rotating charged black holes are described by the Reissner–Nordström metric, while the Kerr metric describes a non-charged rotating black hole. The most general stationary black hole solution known is the Kerr–Newman metric, which describes a black hole with both charge and angular momentum.[75]
|
59 |
+
|
60 |
+
While the mass of a black hole can take any positive value, the charge and angular momentum are constrained by the mass. The total electric charge Q and the total angular momentum J are expected to satisfy the inequality
|
61 |
+
|
62 |
+
Q 2 4 π ϵ 0 + c 2 J 2 G M 2 ≤ G M 2 {\displaystyle {\frac {Q^{2}}{4\pi \epsilon _{0}}}+{\frac {c^{2}J^{2}}{GM^{2}}}\leq GM^{2}}
|
63 |
+
|
64 |
+
for a black hole of mass M. Black holes with the minimum possible mass satisfying this inequality are called extremal. Solutions of Einstein's equations that violate this inequality exist, but they do not possess an event horizon. These solutions have so-called naked singularities that can be observed from the outside, and hence are deemed unphysical. The cosmic censorship hypothesis rules out the formation of such singularities, when they are created through the gravitational collapse of realistic matter.[3] This is supported by numerical simulations.[76]
|
65 |
+
|
66 |
+
Due to the relatively large strength of the electromagnetic force, black holes forming from the collapse of stars are expected to retain the nearly neutral charge of the star. Rotation, however, is expected to be a universal feature of compact astrophysical objects. The black-hole candidate binary X-ray source GRS 1915+105[77] appears to have an angular momentum near the maximum allowed value. That uncharged limit is[78]
|
67 |
+
|
68 |
+
J ≤ G M 2 c , {\displaystyle J\leq {\frac {GM^{2}}{c}},}
|
69 |
+
|
70 |
+
allowing definition of a dimensionless spin parameter such that[78]
|
71 |
+
|
72 |
+
0 ≤ c J G M 2 ≤ 1. {\displaystyle 0\leq {\frac {cJ}{GM^{2}}}\leq 1.}[78][Note 1]
|
73 |
+
|
74 |
+
Black hole classifications Class Approx.
|
75 |
+
mass Approx.
|
76 |
+
radius
|
77 |
+
Ultramassive black hole 109–1011 M☉ >1,000 AU
|
78 |
+
Supermassive black hole 106–109 M☉ 0.001–400 AU
|
79 |
+
Intermediate-mass black hole 102–105 M☉ 103 km ≈ REarth
|
80 |
+
Stellar black hole 2-150 M☉ 30 km
|
81 |
+
Micro black hole up to MMoon up to 0.1 mm
|
82 |
+
|
83 |
+
Black holes are commonly classified according to their mass, independent of angular momentum, J. The size of a black hole, as determined by the radius of the event horizon, or Schwarzschild radius, is proportional to the mass, M, through
|
84 |
+
|
85 |
+
r s = 2 G M c 2 ≈ 2.95 M M ⊙ k m , {\displaystyle r_{\mathrm {s} }={\frac {2GM}{c^{2}}}\approx 2.95\,{\frac {M}{M_{\odot }}}~\mathrm {km,} }
|
86 |
+
|
87 |
+
where rs is the Schwarzschild radius and M☉ is the mass of the Sun.[80] For a black hole with nonzero spin and/or electric charge, the radius is smaller,[Note 2] until an extremal black hole could have an event horizon close to[81]
|
88 |
+
|
89 |
+
r + = G M c 2 . {\displaystyle r_{\mathrm {+} }={\frac {GM}{c^{2}}}.}
|
90 |
+
|
91 |
+
Event horizon
|
92 |
+
Main article: Event horizon
|
93 |
+
Far away from the black hole, a particle can move in any direction, as illustrated by the set of arrows. It is restricted only by the speed of light.
|
94 |
+
Closer to the black hole, spacetime starts to deform. There are more paths going towards the black hole than paths moving away.[Note 3]
|
95 |
+
Inside of the event horizon, all paths bring the particle closer to the centre of the black hole. It is no longer possible for the particle to escape.
|
96 |
+
|
97 |
+
The defining feature of a black hole is the appearance of an event horizon—a boundary in spacetime through which matter and light can pass only inward towards the mass of the black hole. Nothing, not even light, can escape from inside the event horizon.[83][84] The event horizon is referred to as such because if an event occurs within the boundary, information from that event cannot reach an outside observer, making it impossible to determine whether such an event occurred.[85]
|
98 |
+
|
99 |
+
As predicted by general relativity, the presence of a mass deforms spacetime in such a way that the paths taken by particles bend towards the mass.[86] At the event horizon of a black hole, this deformation becomes so strong that there are no paths that lead away from the black hole.[87]
|
100 |
+
|
101 |
+
To a distant observer, clocks near a black hole would appear to tick more slowly than those farther away from the black hole.[88] Due to this effect, known as gravitational time dilation, an object falling into a black hole appears to slow as it approaches the event horizon, taking an infinite time to reach it.[89] At the same time, all processes on this object slow down, from the viewpoint of a fixed outside observer, causing any light emitted by the object to appear redder and dimmer, an effect known as gravitational redshift.[90] Eventually, the falling object fades away until it can no longer be seen. Typically this process happens very rapidly with an object disappearing from view within less than a second.[91]
|
102 |
+
|
103 |
+
On the other hand, indestructible observers falling into a black hole do not notice any of these effects as they cross the event horizon. According to their own clocks, which appear to them to tick normally, they cross the event horizon after a finite time without noting any singular behaviour; in classical general relativity, it is impossible to determine the location of the event horizon from local observations, due to Einstein's equivalence principle.[92][93]
|
104 |
+
|
105 |
+
The topology of the event horizon of a black hole at equilibrium is always spherical.[Note 4][96] For non-rotating (static) black holes the geometry of the event horizon is precisely spherical, while for rotating black holes the event horizon is oblate.[97][98][99]
|
106 |
+
Singularity
|
107 |
+
Main article: Gravitational singularity
|
108 |
+
|
109 |
+
At the centre of a black hole, as described by general relativity, may lie a gravitational singularity, a region where the spacetime curvature becomes infinite.[100] For a non-rotating black hole, this region takes the shape of a single point; for a rotating black hole it is smeared out to form a ring singularity that lies in the plane of rotation.[101] In both cases, the singular region has zero volume. It can also be shown that the singular region contains all the mass of the black hole solution.[102] The singular region can thus be thought of as having infinite density.[103]
|
110 |
+
|
111 |
+
Observers falling into a Schwarzschild black hole (i.e., non-rotating and not charged) cannot avoid being carried into the singularity once they cross the event horizon. They can prolong the experience by accelerating away to slow their descent, but only up to a limit.[104] When they reach the singularity, they are crushed to infinite density and their mass is added to the total of the black hole. Before that happens, they will have been torn apart by the growing tidal forces in a process sometimes referred to as spaghettification or the "noodle effect".[105]
|
112 |
+
|
113 |
+
In the case of a charged (Reissner–Nordström) or rotating (Kerr) black hole, it is possible to avoid the singularity. Extending these solutions as far as possible reveals the hypothetical possibility of exiting the black hole into a different spacetime with the black hole acting as a wormhole.[106] The possibility of traveling to another universe is, however, only theoretical since any perturbation would destroy this possibility.[107] It also appears to be possible to follow closed timelike curves (returning to one's own past) around the Kerr singularity, which leads to problems with causality like the grandfather paradox.[108] It is expected that none of these peculiar effects would survive in a proper quantum treatment of rotating and charged black holes.[109]
|
114 |
+
|
115 |
+
The appearance of singularities in general relativity is commonly perceived as signaling the breakdown of the theory.[110] This breakdown, however, is expected; it occurs in a situation where quantum effects should describe these actions, due to the extremely high density and therefore particle interactions. To date, it has not been possible to combine quantum and gravitational effects into a single theory, although there exist attempts to formulate such a theory of quantum gravity. It is generally expected that such a theory will not feature any singularities.[111][112]
|
116 |
+
Photon sphere
|
117 |
+
Main article: Photon sphere
|
118 |
+
|
119 |
+
The photon sphere is a spherical boundary of zero thickness in which photons that move on tangents to that sphere would be trapped in a circular orbit about the black hole. For non-rotating black holes, the photon sphere has a radius 1.5 times the Schwarzschild radius. Their orbits would be dynamically unstable, hence any small perturbation, such as a particle of infalling matter, would cause an instability that would grow over time, either setting the photon on an outward trajectory causing it to escape the black hole, or on an inward spiral where it would eventually cross the event horizon.[113]
|
120 |
+
|
121 |
+
While light can still escape from the photon sphere, any light that crosses the photon sphere on an inbound trajectory will be captured by the black hole. Hence any light that reaches an outside observer from the photon sphere must have been emitted by objects between the photon sphere and the event horizon.[113] For a Kerr black hole the radius of the photon sphere depends on the spin parameter and on the details of the photon orbit, which can be prograde (the photon rotates in the same sense of the black hole spin) or retrograde.[114][115]
|
122 |
+
Ergosphere
|
123 |
+
Main article: Ergosphere
|
124 |
+
The ergosphere is a region outside of the event horizon, where objects cannot remain in place.[116]
|
125 |
+
|
126 |
+
Rotating black holes are surrounded by a region of spacetime in which it is impossible to stand still, called the ergosphere. This is the result of a process known as frame-dragging; general relativity predicts that any rotating mass will tend to slightly "drag" along the spacetime immediately surrounding it. Any object near the rotating mass will tend to start moving in the direction of rotation. For a rotating black hole, this effect is so strong near the event horizon that an object would have to move faster than the speed of light in the opposite direction to just stand still.[117]
|
127 |
+
|
128 |
+
The ergosphere of a black hole is a volume bounded by the black hole's event horizon and the ergosurface, which coincides with the event horizon at the poles but is at a much greater distance around the equator.[116]
|
129 |
+
|
130 |
+
Objects and radiation can escape normally from the ergosphere. Through the Penrose process, objects can emerge from the ergosphere with more energy than they entered with. The extra energy is taken from the rotational energy of the black hole. Thereby the rotation of the black hole slows down.[118] A variation of the Penrose process in the presence of strong magnetic fields, the Blandford–Znajek process is considered a likely mechanism for the enormous luminosity and relativistic jets of quasars and other active galactic nuclei.
|
131 |
+
Innermost stable circular orbit (ISCO)
|
132 |
+
Main article: Innermost stable circular orbit
|
133 |
+
|
134 |
+
In Newtonian gravity, test particles can stably orbit at arbitrary distances from a central object. In general relativity, however, there exists an innermost stable circular orbit (often called the ISCO), for which any infinitesimal inward perturbations to a circular orbit will lead to spiraling into the black hole, and any outward perturbations will, depending on the energy, result in spiraling in, stably orbiting between apastron and periastron, or escaping to infinity.[119] The location of the ISCO depends on the spin of the black hole, in the case of a Schwarzschild black hole (spin zero) is:
|
135 |
+
|
136 |
+
r I S C O = 3 r s = 6 G M c 2 , {\displaystyle r_{\rm {ISCO}}=3\,r_{s}={\frac {6\,GM}{c^{2}}},}
|
137 |
+
|
138 |
+
and decreases with increasing black hole spin for particles orbiting in the same direction as the spin.[120]
|
139 |
+
Formation and evolution
|
140 |
+
|
141 |
+
Given the bizarre character of black holes, it was long questioned whether such objects could actually exist in nature or whether they were merely pathological solutions to Einstein's equations. Einstein himself wrongly thought black holes would not form, because he held that the angular momentum of collapsing particles would stabilize their motion at some radius.[121] This led the general relativity community to dismiss all results to the contrary for many years. However, a minority of relativists continued to contend that black holes were physical objects,[122] and by the end of the 1960s, they had persuaded the majority of researchers in the field that there is no obstacle to the formation of an event horizon.[123]
|
142 |
+
Simulation of two black holes colliding
|
143 |
+
|
144 |
+
Penrose demonstrated that once an event horizon forms, general relativity without quantum mechanics requires that a singularity will form within.[49] Shortly afterwards, Hawking showed that many cosmological solutions that describe the Big Bang have singularities without scalar fields or other exotic matter.[clarification needed] The Kerr solution, the no-hair theorem, and the laws of black hole thermodynamics showed that the physical properties of black holes were simple and comprehensible, making them respectable subjects for research.[124] Conventional black holes are formed by gravitational collapse of heavy objects such as stars, but they can also in theory be formed by other processes.[125][126]
|
145 |
+
Gravitational collapse
|
146 |
+
Main article: Gravitational collapse
|
147 |
+
Gas cloud being ripped apart by black hole at the centre of the Milky Way (observations from 2006, 2010 and 2013 are shown in blue, green and red, respectively).[127]
|
148 |
+
|
149 |
+
Gravitational collapse occurs when an object's internal pressure is insufficient to resist the object's own gravity. For stars this usually occurs either because a star has too little "fuel" left to maintain its temperature through stellar nucleosynthesis, or because a star that would have been stable receives extra matter in a way that does not raise its core temperature. In either case the star's temperature is no longer high enough to prevent it from collapsing under its own weight.[128] The collapse may be stopped by the degeneracy pressure of the star's constituents, allowing the condensation of matter into an exotic denser state. The result is one of the various types of compact star. Which type forms depends on the mass of the remnant of the original star left if the outer layers have been blown away (for example, in a Type II supernova). The mass of the remnant, the collapsed object that survives the explosion, can be substantially less than that of the original star. Remnants exceeding 5 M☉ are produced by stars that were over 20 M☉ before the collapse.[128]
|
150 |
+
|
151 |
+
If the mass of the remnant exceeds about 3–4 M☉ (the Tolman–Oppenheimer–Volkoff limit[28]), either because the original star was very heavy or because the remnant collected additional mass through accretion of matter, even the degeneracy pressure of neutrons is insufficient to stop the collapse. No known mechanism (except possibly quark degeneracy pressure) is powerful enough to stop the implosion and the object will inevitably collapse to form a black hole.[128]
|
152 |
+
Artist's impression of supermassive black hole seed[129]
|
153 |
+
|
154 |
+
The gravitational collapse of heavy stars is assumed to be responsible for the formation of stellar mass black holes. Star formation in the early universe may have resulted in very massive stars, which upon their collapse would have produced black holes of up to 103 M☉. These black holes could be the seeds of the supermassive black holes found in the centres of most galaxies.[130] It has further been suggested that massive black holes with typical masses of ~105 M☉ could have formed from the direct collapse of gas clouds in the young universe.[125] These massive objects have been proposed as the seeds that eventually formed the earliest quasars observed already at redshift z ∼ 7 {\displaystyle z\sim 7}.[131] Some candidates for such objects have been found in observations of the young universe.[125]
|
155 |
+
|
156 |
+
While most of the energy released during gravitational collapse is emitted very quickly, an outside observer does not actually see the end of this process. Even though the collapse takes a finite amount of time from the reference frame of infalling matter, a distant observer would see the infalling material slow and halt just above the event horizon, due to gravitational time dilation. Light from the collapsing material takes longer and longer to reach the observer, with the light emitted just before the event horizon forms delayed an infinite amount of time. Thus the external observer never sees the formation of the event horizon; instead, the collapsing material seems to become dimmer and increasingly red-shifted, eventually fading away.[132]
|
157 |
+
Primordial black holes and the Big Bang
|
158 |
+
|
159 |
+
Gravitational collapse requires great density. In the current epoch of the universe these high densities are found only in stars, but in the early universe shortly after the Big Bang densities were much greater, possibly allowing for the creation of black holes. High density alone is not enough to allow black hole formation since a uniform mass distribution will not allow the mass to bunch up. In order for primordial black holes to have formed in such a dense medium, there must have been initial density perturbations that could then grow under their own gravity. Different models for the early universe vary widely in their predictions of the scale of these fluctuations. Various models predict the creation of primordial black holes ranging in size from a Planck mass ( m P = ℏ c / G {\displaystyle m_{P}={\sqrt {\hbar c/G}}} ≈ 1.2×1019 GeV/c2 ≈ 2.2×10−8 kg) to hundreds of thousands of solar masses.[126]
|
160 |
+
|
161 |
+
Despite the early universe being extremely dense, it did not re-collapse into a black hole during the Big Bang, since the expansion rate was greater than the attraction. Following inflation theory there was a net repulsive gravitation in the beginning until the end of inflation. Since then the Hubble flow was slowed by the energy density of the universe.
|
162 |
+
|
163 |
+
Models for the gravitational collapse of objects of relatively constant size, such as stars, do not necessarily apply in the same way to rapidly expanding space such as the Big Bang.[133]
|
164 |
+
High-energy collisions
|
165 |
+
Simulated event in the CMS detector: a collision in which a micro black hole may be created
|
166 |
+
|
167 |
+
Gravitational collapse is not the only process that could create black holes. In principle, black holes could be formed in high-energy collisions that achieve sufficient density. As of 2002, no such events have been detected, either directly or indirectly as a deficiency of the mass balance in particle accelerator experiments.[134] This suggests that there must be a lower limit for the mass of black holes. Theoretically, this boundary is expected to lie around the Planck mass, where quantum effects are expected to invalidate the predictions of general relativity.[135] This would put the creation of black holes firmly out of reach of any high-energy process occurring on or near the Earth. However, certain developments in quantum gravity suggest that the minimum black hole mass could be much lower: some braneworld scenarios for example put the boundary as low as 1 TeV/c2.[136] This would make it conceivable for micro black holes to be created in the high-energy collisions that occur when cosmic rays hit the Earth's atmosphere, or possibly in the Large Hadron Collider at CERN. These theories are very speculative, and the creation of black holes in these processes is deemed unlikely by many specialists.[137] Even if micro black holes could be formed, it is expected that they would evaporate in about 10−25 seconds, posing no threat to the Earth.[138]
|
168 |
+
Growth
|
169 |
+
|
170 |
+
Once a black hole has formed, it can continue to grow by absorbing additional matter. Any black hole will continually absorb gas and interstellar dust from its surroundings. This growth process is one possible way through which some supermassive black holes may have been formed, although the formation of supermassive black holes is still an open field of research.[130] A similar process has been suggested for the formation of intermediate-mass black holes found in globular clusters.[139] Black holes can also merge with other objects such as stars or even other black holes. This is thought to have been important, especially in the early growth of supermassive black holes, which could have formed from the aggregation of many smaller objects.[130] The process has also been proposed as the origin of some intermediate-mass black holes.[140][141]
|
171 |
+
Evaporation
|
172 |
+
Main article: Hawking radiation
|
173 |
+
|
174 |
+
In 1974, Hawking predicted that black holes are not entirely black but emit small amounts of thermal radiation at a temperature ℏc3/(8πGMkB);[55] this effect has become known as Hawking radiation. By applying quantum field theory to a static black hole background, he determined that a black hole should emit particles that display a perfect black body spectrum. Since Hawking's publication, many others have verified the result through various approaches.[142] If Hawking's theory of black hole radiation is correct, then black holes are expected to shrink and evaporate over time as they lose mass by the emission of photons and other particles.[55] The temperature of this thermal spectrum (Hawking temperature) is proportional to the surface gravity of the black hole, which, for a Schwarzschild black hole, is inversely proportional to the mass. Hence, large black holes emit less radiation than small black holes.[143]
|
175 |
+
|
176 |
+
A stellar black hole of 1 M☉ has a Hawking temperature of 62 nanokelvins.[144] This is far less than the 2.7 K temperature of the cosmic microwave background radiation. Stellar-mass or larger black holes receive more mass from the cosmic microwave background than they emit through Hawking radiation and thus will grow instead of shrinking.[145] To have a Hawking temperature larger than 2.7 K (and be able to evaporate), a black hole would need a mass less than the Moon. Such a black hole would have a diameter of less than a tenth of a millimeter.[146]
|
177 |
+
|
178 |
+
If a black hole is very small, the radiation effects are expected to become very strong. A black hole with the mass of a car would have a diameter of about 10−24 m and take a nanosecond to evaporate, during which time it would briefly have a luminosity of more than 200 times that of the Sun. Lower-mass black holes are expected to evaporate even faster; for example, a black hole of mass 1 TeV/c2 would take less than 10−88 seconds to evaporate completely. For such a small black hole, quantum gravity effects are expected to play an important role and could hypothetically make such a small black hole stable, although current developments in quantum gravity do not indicate this is the case.[147][148]
|
179 |
+
|
180 |
+
The Hawking radiation for an astrophysical black hole is predicted to be very weak and would thus be exceedingly difficult to detect from Earth. A possible exception, however, is the burst of gamma rays emitted in the last stage of the evaporation of primordial black holes. Searches for such flashes have proven unsuccessful and provide stringent limits on the possibility of existence of low mass primordial black holes.[149] NASA's Fermi Gamma-ray Space Telescope launched in 2008 will continue the search for these flashes.[150]
|
181 |
+
|
182 |
+
If black holes evaporate via Hawking radiation, a solar mass black hole will evaporate (beginning once the temperature of the cosmic microwave background drops below that of the black hole) over a period of 1064 years.[151] A supermassive black hole with a mass of 1011 M☉ will evaporate in around 2×10100 years.[152] Some monster black holes in the universe are predicted to continue to grow up to perhaps 1014 M☉ during the collapse of superclusters of galaxies. Even these would evaporate over a timescale of up to 10106 years.[151]
|
183 |
+
|
184 |
+
Some models of quantum gravity predict modifications of the Hawking description of black holes. In particular, the evolution equations describing the mass loss rate and charge loss rate get modified.[153]
|
185 |
+
Observational evidence
|
186 |
+
|
187 |
+
By nature, black holes do not themselves emit any electromagnetic radiation other than the hypothetical Hawking radiation, so astrophysicists searching for black holes must generally rely on indirect observations. For example, a black hole's existence can sometimes be inferred by observing its gravitational influence on its surroundings.[154]
|
188 |
+
|
189 |
+
On 10 April 2019, an image was released of a black hole, which is seen magnified because the light paths near the event horizon are highly bent. The dark shadow in the middle results from light paths absorbed by the black hole.[155] The image is in false color, as the detected light halo in this image is not in the visible spectrum, but radio waves.
|
190 |
+
Artist's impression of the closest black hole to Earth and its Sun-like companion star
|
191 |
+
This artist's impression depicts the paths of photons in the vicinity of a black hole. The gravitational bending and capture of light by the event horizon is the cause of the shadow captured by the Event Horizon Telescope.
|
192 |
+
|
193 |
+
The Event Horizon Telescope (EHT) is an active program that directly observes the immediate environment of black holes' event horizons, such as the black hole at the centre of the Milky Way. In April 2017, EHT began observing the black hole at the centre of Messier 87.[156] "In all, eight radio observatories on six mountains and four continents observed the galaxy in Virgo on and off for 10 days in April 2017" to provide the data yielding the image in April 2019.[157] After two years of data processing, EHT released the first direct image of a black hole; specifically, the supermassive black hole that lies in the centre of the aforementioned galaxy.[158][159] What is visible is not the black hole—which shows as black because of the loss of all light within this dark region. Instead, it is the gases at the edge of the event horizon (displayed as orange or red) that define the black hole.[160]
|
194 |
+
|
195 |
+
On 12 May 2022, the EHT released the first image of Sagittarius A*, the supermassive black hole at the centre of the Milky Way galaxy. The published image displayed the same ring-like structure and circular shadow as seen in the M87* black hole, and the image was created using the same techniques as for the M87 black hole. However, the imaging process for Sagittarius A*, which is more than a thousand times smaller and less massive than M87*, was significantly more complex because of the instability of its surroundings.[161] The image of Sagittarius A* was also partially blurred by turbulent plasma on the way to the galactic centre, an effect which prevents resolution of the image at longer wavelengths.[162]
|
196 |
+
|
197 |
+
The brightening of this material in the 'bottom' half of the processed EHT image is thought to be caused by Doppler beaming, whereby material approaching the viewer at relativistic speeds is perceived as brighter than material moving away. In the case of a black hole, this phenomenon implies that the visible material is rotating at relativistic speeds (>1,000 km/s [2,200,000 mph]), the only speeds at which it is possible to centrifugally balance the immense gravitational attraction of the singularity, and thereby remain in orbit above the event horizon. This configuration of bright material implies that the EHT observed M87* from a perspective catching the black hole's accretion disc nearly edge-on, as the whole system rotated clockwise.[163][164] However, the extreme gravitational lensing associated with black holes produces the illusion of a perspective that sees the accretion disc from above. In reality, most of the ring in the EHT image was created when the light emitted by the far side of the accretion disc bent around the black hole's gravity well and escaped, meaning that most of the possible perspectives on M87* can see the entire disc, even that directly behind the "shadow".
|
198 |
+
|
199 |
+
In 2015, the EHT detected magnetic fields just outside the event horizon of Sagittarius A* and even discerned some of their properties. The field lines that pass through the accretion disc were a complex mixture of ordered and tangled. Theoretical studies of black holes had predicted the existence of magnetic fields.[165][166]
|
200 |
+
Predicted appearance of a non-rotating black hole with toroidal ring of ionised matter, such as has been proposed[167] as a model for Sagittarius A*. The asymmetry is due to the Doppler effect resulting from the enormous orbital speed needed for centrifugal balance of the powerful gravitational attraction of the hole.
|
201 |
+
|
202 |
+
In April 2023, an image of the shadow of the Messier 87 black hole and the related high-energy jet, viewed together for the first time, was presented.[168][169]
|
203 |
+
Detection of gravitational waves from merging black holes
|
204 |
+
|
205 |
+
On 14 September 2015, the LIGO gravitational wave observatory made the first-ever successful direct observation of gravitational waves.[56][170] The signal was consistent with theoretical predictions for the gravitational waves produced by the merger of two black holes: one with about 36 solar masses, and the other around 29 solar masses.[56][171] This observation provides the most concrete evidence for the existence of black holes to date. For instance, the gravitational wave signal suggests that the separation of the two objects before the merger was just 350 km (or roughly four times the Schwarzschild radius corresponding to the inferred masses). The objects must therefore have been extremely compact, leaving black holes as the most plausible interpretation.[56]
|
206 |
+
|
207 |
+
More importantly, the signal observed by LIGO also included the start of the post-merger ringdown, the signal produced as the newly formed compact object settles down to a stationary state. Arguably, the ringdown is the most direct way of observing a black hole.[172] From the LIGO signal, it is possible to extract the frequency and damping time of the dominant mode of the ringdown. From these, it is possible to infer the mass and angular momentum of the final object, which match independent predictions from numerical simulations of the merger.[173] The frequency and decay time of the dominant mode are determined by the geometry of the photon sphere. Hence, observation of this mode confirms the presence of a photon sphere; however, it cannot exclude possible exotic alternatives to black holes that are compact enough to have a photon sphere.[172]
|
208 |
+
|
209 |
+
The observation also provides the first observational evidence for the existence of stellar-mass black hole binaries. Furthermore, it is the first observational evidence of stellar-mass black holes weighing 25 solar masses or more.[174]
|
210 |
+
|
211 |
+
Since then, many more gravitational wave events have been observed.[175]
|
212 |
+
Proper motions of stars orbiting Sagittarius A*
|
213 |
+
|
214 |
+
The proper motions of stars near the centre of our own Milky Way provide strong observational evidence that these stars are orbiting a supermassive black hole.[176] Since 1995, astronomers have tracked the motions of 90 stars orbiting an invisible object coincident with the radio source Sagittarius A*. By fitting their motions to Keplerian orbits, the astronomers were able to infer, in 1998, that a 2.6×106 M☉ object must be contained in a volume with a radius of 0.02 light-years to cause the motions of those stars.[177] Since then, one of the stars—called S2—has completed a full orbit. From the orbital data, astronomers were able to refine the calculations of the mass to 4.3×106 M☉ and a radius of less than 0.002 light-years for the object causing the orbital motion of those stars.[176] The upper limit on the object's size is still too large to test whether it is smaller than its Schwarzschild radius; nevertheless, these observations strongly suggest that the central object is a supermassive black hole as there are no other plausible scenarios for confining so much invisible mass into such a small volume.[177] Additionally, there is some observational evidence that this object might possess an event horizon, a feature unique to black holes.[178]
|
215 |
+
Accretion of matter
|
216 |
+
See also: Accretion disk
|
217 |
+
Black hole with corona, X-ray source (artist's concept)[179]
|
218 |
+
|
219 |
+
Due to conservation of angular momentum,[180] gas falling into the gravitational well created by a massive object will typically form a disk-like structure around the object. Artists' impressions such as the accompanying representation of a black hole with corona commonly depict the black hole as if it were a flat-space body hiding the part of the disk just behind it, but in reality gravitational lensing would greatly distort the image of the accretion disk.[181]
|
220 |
+
NASA simulated view from outside the horizon of a Schwarzschild black hole lit by a thin accretion disk.
|
221 |
+
|
222 |
+
Within such a disk, friction would cause angular momentum to be transported outward, allowing matter to fall farther inward, thus releasing potential energy and increasing the temperature of the gas.[182]
|
223 |
+
Blurring of X-rays near black hole (NuSTAR; 12 August 2014)[179]
|
224 |
+
|
225 |
+
When the accreting object is a neutron star or a black hole, the gas in the inner accretion disk orbits at very high speeds because of its proximity to the compact object. The resulting friction is so significant that it heats the inner disk to temperatures at which it emits vast amounts of electromagnetic radiation (mainly X-rays). These bright X-ray sources may be detected by telescopes. This process of accretion is one of the most efficient energy-producing processes known; up to 40% of the rest mass of the accreted material can be emitted as radiation.[182] (In nuclear fusion only about 0.7% of the rest mass will be emitted as energy.) In many cases, accretion disks are accompanied by relativistic jets that are emitted along the poles, which carry away much of the energy. The mechanism for the creation of these jets is currently not well understood, in part due to insufficient data.[183]
|
226 |
+
|
227 |
+
As such, many of the universe's more energetic phenomena have been attributed to the accretion of matter on black holes. In particular, active galactic nuclei and quasars are believed to be the accretion disks of supermassive black holes.[184] Similarly, X-ray binaries are generally accepted to be binary star systems in which one of the two stars is a compact object accreting matter from its companion.[184] It has also been suggested that some ultraluminous X-ray sources may be the accretion disks of intermediate-mass black holes.[185]
|
228 |
+
|
229 |
+
In November 2011 the first direct observation of a quasar accretion disk around a supermassive black hole was reported.[186][187]
|
230 |
+
X-ray binaries
|
231 |
+
See also: X-ray binary
|
232 |
+
Computer simulation of a star being consumed by a black hole. The blue dot indicates the location of the black hole.
|
233 |
+
This animation compares the X-ray "heartbeats" of GRS 1915 and IGR J17091, two black holes that ingest gas from companion stars.
|
234 |
+
A Chandra X-Ray Observatory image of Cygnus X-1, which was the first strong black hole candidate discovered
|
235 |
+
|
236 |
+
X-ray binaries are binary star systems that emit a majority of their radiation in the X-ray part of the spectrum. These X-ray emissions are generally thought to result when one of the stars (compact object) accretes matter from another (regular) star. The presence of an ordinary star in such a system provides an opportunity for studying the central object and to determine if it might be a black hole.[184]
|
237 |
+
|
238 |
+
If such a system emits signals that can be directly traced back to the compact object, it cannot be a black hole. The absence of such a signal does, however, not exclude the possibility that the compact object is a neutron star. By studying the companion star it is often possible to obtain the orbital parameters of the system and to obtain an estimate for the mass of the compact object. If this is much larger than the Tolman–Oppenheimer–Volkoff limit (the maximum mass a star can have without collapsing) then the object cannot be a neutron star and is generally expected to be a black hole.[184]
|
239 |
+
|
240 |
+
The first strong candidate for a black hole, Cygnus X-1, was discovered in this way by Charles Thomas Bolton,[188] Louise Webster, and Paul Murdin[189] in 1972.[190][191] Some doubt, however, remained due to the uncertainties that result from the companion star being much heavier than the candidate black hole. Currently, better candidates for black holes are found in a class of X-ray binaries called soft X-ray transients. In this class of system, the companion star is of relatively low mass allowing for more accurate estimates of the black hole mass. Moreover, these systems actively emit X-rays for only several months once every 10–50 years. During the period of low X-ray emission (called quiescence), the accretion disk is extremely faint allowing detailed observation of the companion star during this period. One of the best such candidates is V404 Cygni.[184]
|
241 |
+
Quasi-periodic oscillations
|
242 |
+
Main article: Quasi-periodic oscillation
|
243 |
+
|
244 |
+
The X-ray emissions from accretion disks sometimes flicker at certain frequencies. These signals are called quasi-periodic oscillations and are thought to be caused by material moving along the inner edge of the accretion disk (the innermost stable circular orbit). As such their frequency is linked to the mass of the compact object. They can thus be used as an alternative way to determine the mass of candidate black holes.[192]
|
245 |
+
Galactic nuclei
|
246 |
+
See also: Active galactic nucleus
|
247 |
+
Magnetic waves, called Alfvén S-waves, flow from the base of black hole jets.
|
248 |
+
|
249 |
+
Astronomers use the term "active galaxy" to describe galaxies with unusual characteristics, such as unusual spectral line emission and very strong radio emission. Theoretical and observational studies have shown that the activity in these active galactic nuclei (AGN) may be explained by the presence of supermassive black holes, which can be millions of times more massive than stellar ones. The models of these AGN consist of a central black hole that may be millions or billions of times more massive than the Sun; a disk of interstellar gas and dust called an accretion disk; and two jets perpendicular to the accretion disk.[193][194]
|
250 |
+
Detection of unusually bright X-ray flare from Sagittarius A*, a black hole in the centre of the Milky Way galaxy on 5 January 2015[195]
|
251 |
+
|
252 |
+
Although supermassive black holes are expected to be found in most AGN, only some galaxies' nuclei have been more carefully studied in attempts to both identify and measure the actual masses of the central supermassive black hole candidates. Some of the most notable galaxies with supermassive black hole candidates include the Andromeda Galaxy, M32, M87, NGC 3115, NGC 3377, NGC 4258, NGC 4889, NGC 1277, OJ 287, APM 08279+5255 and the Sombrero Galaxy.[196]
|
253 |
+
|
254 |
+
It is now widely accepted that the centre of nearly every galaxy, not just active ones, contains a supermassive black hole.[197] The close observational correlation between the mass of this hole and the velocity dispersion of the host galaxy's bulge, known as the M–sigma relation, strongly suggests a connection between the formation of the black hole and that of the galaxy itself.[198]
|
255 |
+
Simulation of gas cloud after close approach to the black hole at the centre of the Milky Way.[199]
|
256 |
+
Microlensing
|
257 |
+
|
258 |
+
Another way the black hole nature of an object may be tested is through observation of effects caused by a strong gravitational field in their vicinity. One such effect is gravitational lensing: The deformation of spacetime around a massive object causes light rays to be deflected, such as light passing through an optic lens. Observations have been made of weak gravitational lensing, in which light rays are deflected by only a few arcseconds. Microlensing occurs when the sources are unresolved and the observer sees a small brightening. In January 2022, astronomers reported the first possible detection of a microlensing event from an isolated black hole.[200]
|
259 |
+
|
260 |
+
Another possibility for observing gravitational lensing by a black hole would be to observe stars orbiting the black hole. There are several candidates for such an observation in orbit around Sagittarius A*.[201]
|
261 |
+
Alternatives
|
262 |
+
See also: Exotic star
|
263 |
+
|
264 |
+
The evidence for stellar black holes strongly relies on the existence of an upper limit for the mass of a neutron star. The size of this limit heavily depends on the assumptions made about the properties of dense matter. New exotic phases of matter could push up this bound.[184] A phase of free quarks at high density might allow the existence of dense quark stars,[202] and some supersymmetric models predict the existence of Q stars.[203] Some extensions of the standard model posit the existence of preons as fundamental building blocks of quarks and leptons, which could hypothetically form preon stars.[204] These hypothetical models could potentially explain a number of observations of stellar black hole candidates. However, it can be shown from arguments in general relativity that any such object will have a maximum mass.[184]
|
265 |
+
|
266 |
+
Since the average density of a black hole inside its Schwarzschild radius is inversely proportional to the square of its mass, supermassive black holes are much less dense than stellar black holes (the average density of a 108 M☉ black hole is comparable to that of water).[184] Consequently, the physics of matter forming a supermassive black hole is much better understood and the possible alternative explanations for supermassive black hole observations are much more mundane. For example, a supermassive black hole could be modelled by a large cluster of very dark objects. However, such alternatives are typically not stable enough to explain the supermassive black hole candidates.[184]
|
267 |
+
|
268 |
+
The evidence for the existence of stellar and supermassive black holes implies that in order for black holes to not form, general relativity must fail as a theory of gravity, perhaps due to the onset of quantum mechanical corrections. A much anticipated feature of a theory of quantum gravity is that it will not feature singularities or event horizons and thus black holes would not be real artifacts. For example, in the fuzzball model based on string theory, the individual states of a black hole solution do not generally have an event horizon or singularity, but for a classical/semi-classical observer the statistical average of such states appears just as an ordinary black hole as deduced from general relativity.
|
269 |
+
|
270 |
+
A few theoretical objects have been conjectured to match observations of astronomical black hole candidates identically or near-identically, but which function via a different mechanism. These include the gravastar, the black star,[207] and the dark-energy star.
|
271 |
+
Open questions
|
272 |
+
Entropy and thermodynamics
|
273 |
+
Further information: Black hole thermodynamics and Bekenstein bound
|
274 |
+
S = 1/4 c3k/Għ A
|
275 |
+
The formula for the Bekenstein–Hawking entropy (S) of a black hole, which depends on the area of the black hole (A). The constants are the speed of light (c), the Boltzmann constant (k), Newton's constant (G), and the reduced Planck constant (ħ). In Planck units, this reduces to S = A/4.
|
276 |
+
|
277 |
+
In 1971, Hawking showed under general conditions[Note 5] that the total area of the event horizons of any collection of classical black holes can never decrease, even if they collide and merge.[209] This result, now known as the second law of black hole mechanics, is remarkably similar to the second law of thermodynamics, which states that the total entropy of an isolated system can never decrease. As with classical objects at absolute zero temperature, it was assumed that black holes had zero entropy. If this were the case, the second law of thermodynamics would be violated by entropy-laden matter entering a black hole, resulting in a decrease in the total entropy of the universe. Therefore, Bekenstein proposed that a black hole should have an entropy, and that it should be proportional to its horizon area.
|
278 |
+
|
279 |
+
The link with the laws of thermodynamics was further strengthened by Hawking's discovery in 1974 that quantum field theory predicts that a black hole radiates blackbody radiation at a constant temperature. This seemingly causes a violation of the second law of black hole mechanics, since the radiation will carry away energy from the black hole causing it to shrink. The radiation, however also carries away entropy, and it can be proven under general assumptions that the sum of the entropy of the matter surrounding a black hole and one quarter of the area of the horizon as measured in Planck units is in fact always increasing. This allows the formulation of the first law of black hole mechanics as an analogue of the first law of thermodynamics, with the mass acting as energy, the surface gravity as temperature and the area as entropy.
|
280 |
+
|
281 |
+
One puzzling feature is that the entropy of a black hole scales with its area rather than with its volume, since entropy is normally an extensive quantity that scales linearly with the volume of the system. This odd property led Gerard 't Hooft and Leonard Susskind to propose the holographic principle, which suggests that anything that happens in a volume of spacetime can be described by data on the boundary of that volume.
|
282 |
+
|
283 |
+
Although general relativity can be used to perform a semi-classical calculation of black hole entropy, this situation is theoretically unsatisfying. In statistical mechanics, entropy is understood as counting the number of microscopic configurations of a system that have the same macroscopic qualities (such as mass, charge, pressure, etc.). Without a satisfactory theory of quantum gravity, one cannot perform such a computation for black holes. Some progress has been made in various approaches to quantum gravity. In 1995, Andrew Strominger and Cumrun Vafa showed that counting the microstates of a specific supersymmetric black hole in string theory reproduced the Bekenstein–Hawking entropy.[212] Since then, similar results have been reported for different black holes both in string theory and in other approaches to quantum gravity like loop quantum gravity.
|
284 |
+
|
285 |
+
Another promising approach is constituted by treating gravity as an effective field theory. One first computes the quantum gravitational corrections to the radius of the event horizon of the black hole, then integrates over it to find the quantum gravitational corrections to the entropy as given by the Wald formula. The method was applied for Schwarzschild black holes by Calmet and Kuipers,[214] then successfully generalised for charged black holes by Campos Delgado.
|
286 |
+
|
287 |
+
Because a black hole has only a few internal parameters, most of the information about the matter that went into forming the black hole is lost. Regardless of the type of matter which goes into a black hole, it appears that only information concerning the total mass, charge, and angular momentum are conserved. As long as black holes were thought to persist forever this information loss is not that problematic, as the information can be thought of as existing inside the black hole, inaccessible from the outside, but represented on the event horizon in accordance with the holographic principle. However, black holes slowly evaporate by emitting Hawking radiation. This radiation does not appear to carry any additional information about the matter that formed the black hole, meaning that this information appears to be gone forever.
|
288 |
+
|
289 |
+
The question whether information is truly lost in black holes (the black hole information paradox) has divided the theoretical physics community. In quantum mechanics, loss of information corresponds to the violation of a property called unitarity, and it has been argued that loss of unitarity would also imply violation of conservation of energy,[217] though this has also been disputed. Over recent years evidence has been building that indeed information and unitarity are preserved in a full quantum gravitational treatment of the problem.
|
290 |
+
|
291 |
+
One attempt to resolve the black hole information paradox is known as black hole complementarity. In 2012, the "firewall paradox" was introduced with the goal of demonstrating that black hole complementarity fails to solve the information paradox. According to quantum field theory in curved spacetime, a single emission of Hawking radiation involves two mutually entangled particles. The outgoing particle escapes and is emitted as a quantum of Hawking radiation; the infalling particle is swallowed by the black hole. Assume a black hole formed a finite time in the past and will fully evaporate away in some finite time in the future. Then, it will emit only a finite amount of information encoded within its Hawking radiation. According to research by physicists like Don Page and Leonard Susskind, there will eventually be a time by which an outgoing particle must be entangled with all the Hawking radiation the black hole has previously emitted. This seemingly creates a paradox: a principle called "monogamy of entanglement" requires that, like any quantum system, the outgoing particle cannot be fully entangled with two other systems at the same time; yet here the outgoing particle appears to be entangled both with the infalling particle and, independently, with past Hawking radiation. In order to resolve this contradiction, physicists may eventually be forced to give up one of three time-tested principles: Einstein's equivalence principle, unitarity, or local quantum field theory. One possible solution, which violates the equivalence principle, is that a "firewall" destroys incoming particles at the event horizon. In general, which—if any—of these assumptions should be abandoned remains a topic of debate.
|
docs/bh2.txt
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The Varieties of Black Holes
|
2 |
+
|
3 |
+
Black holes come in three categories:
|
4 |
+
|
5 |
+
Stellar Mass Black Holes are born from the death of stars much more massive than the Sun. When some of these stars run out of the nuclear fuel that makes them shine, their cores collapse into black holes under their own gravity. Other stellar mass black holes form from the collision of neutron stars, such as the ones first detected by LIGO and Virgo in 2017. These are probably the most common black holes in the cosmos, but are hard to detect unless they have an ordinary star for a companion. When that happens, the black hole can strip material from the star, causing the gas to heat up and glow brightly in X-rays.
|
6 |
+
|
7 |
+
Supermassive Black Holes are the monsters of the universe, living at the centers of nearly every galaxy. They range in mass from 100,000 to billions of times the mass of the Sun, far too massive to be born from a single star. The Milky Way’s black hole is about 4 million times the Sun’s mass, putting it in the middle of the pack. In the form of quasars and other “active” galaxies, these black holes can shine brightly enough to be seen from billions of light-years away. Understanding when these black holes formed and how they grow is a major area of research. Center for Astrophysics | Harvard & Smithsonian scientists are part of the Event Horizon Telescope (EHT) collaboration, which captured the first-ever image of the black hole: the supermassive black hole at the center of the galaxy M87.
|
8 |
+
|
9 |
+
Intermediate Mass Black Holes are the most mysterious, since we’ve hardly seen any of them yet. They weigh 100 to 10,000 times the mass of the Sun, putting them between stellar and supermassive black holes. We don’t know exactly how many of these are, and like supermassive black holes, we don’t fully understand how they’re born or grow. However, studying them could tell us a lot about how the most supermassive black holes came to be.
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
Black holes can seem bizarre and incomprehensible, but in truth they’re remarkably understandable. Despite not being able to see black holes directly, we know quite a bit about them. They are …
|
14 |
+
|
15 |
+
Simple. All three black hole types can be described by just two observable quantities: their mass and how fast they spin. That’s much simpler than a star, for example, which in addition to mass is a product of its unique history and evolution, including its chemical makeup. Mass and spin tell us everything we need to know about a black hole: it “forgets” everything that went into making it. Those two quantities determine how big the event horizon is, and the way gravity affects any matter falling onto the black hole.
|
16 |
+
|
17 |
+
Compact. Black holes are tiny compared to their mass. The event horizon of a black hole the mass of the Sun would be no more than 6 kilometers across, and the faster it spins, the smaller that size is. Even a supermassive black hole would fit easily inside our Solar System.
|
18 |
+
|
19 |
+
Powerful. The combination of large mass and small size results in very strong gravity. This gravity is strong enough to pull a star apart if it gets too close, producing powerful bursts of light. A supermassive black hole heats gas falling onto it to temperatures of millions of degrees, making it glow brightly enough in X-rays and other types of radiation to be seen across the universe.
|
20 |
+
|
21 |
+
Very common. From theoretical calculations based on observations, astronomers think the Milky Way might have as many as a hundred million black holes, most of which are stellar mass. And with at least one supermassive black hole in most galaxies, there could be hundreds of billions of supermassive black holes in the observable universe.
|
22 |
+
|
23 |
+
Very important. Black holes have a reputation for eating everything that comes by, but they turn out to be messy eaters. A lot of stuff that falls toward a black hole gets jetted away, thanks to the complicated churning of gas near the event horizon. These jets and outflows of gas called “winds” spread atoms throughout the galaxy, and can either boost or throttle the birth of new stars, depending on other factors. That means supermassive black holes play an important role in the life of galaxies, even far beyond the black hole’s gravitational pull.
|
24 |
+
|
25 |
+
And yes, mysterious. Along with astronomers, physicists are interested in black holes because they’re a laboratory for “quantum gravity”. Black holes are described by Albert Einstein’s general relativity, which is our modern theory of gravity, but the other forces of nature are described by quantum physics. So far, nobody has developed a complete quantum gravity theory, but we already know black holes will be an important test of any proposed theory.
|
docs/bh3.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
r
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
1 |
+
1 Introduction
|
2 |
+
|
3 |
+
O(r), W = O(r2), S =
|
4 |
+
O(r), (11)
|
5 |
+
ζ2
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
H(r)
|
11 |
r
|
12 |
+
Ψdθ2 + sin2 θ
|
13 |
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
2f
|
21 |
+
8αrf′ + r2
|
22 |
+
4αr2f′2 + αr4f′′2 − 20αf2 − 2r2,
|
23 |
+
2f
|
24 |
+
8αrf′ + r2
|
25 |
+
4αr2f′2 + αr4f′′2 + 28αf2 − 2r2,
|
26 |
+
r2
|
27 |
+
4αf
|
28 |
+
8rf′ + 6
|
29 |
+
8αr2f′2 + r4f′′ (1 − αf′′) − 28αf2.
|
30 |
+
2f′
|
31 |
+
r2 (rf′′ − 2f′)2 − 2r4f(3)f′ + 4f2 − 4,
|
32 |
+
2rf
|
33 |
+
4f′
|
34 |
+
|
35 |
+
|
36 |
+
c2
|
37 |
+
(π −
|
38 |
+
ϕ0, (81)
|
39 |
|
40 |
+
|
41 |
+
O(r3), R ∼ −
|
42 |
+
O (r) (85)
|
43 |
+
2πl2 ln
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
matplotlib
|
3 |
+
plotly
|
4 |
+
pandas
|
5 |
+
scipy
|
6 |
+
scikit-learn
|
7 |
+
python-dotenv
|
8 |
+
openai
|
9 |
+
chainlit
|
10 |
+
wandb
|
11 |
+
click
|
utils/__pycache__/text_utils.cpython-311.pyc
ADDED
Binary file (5.41 kB). View file
|
|
utils/__pycache__/vectordatabase.cpython-311.pyc
ADDED
Binary file (5.7 kB). View file
|
|
utils/openai_utils/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
utils/openai_utils/__init__.py
ADDED
File without changes
|
utils/openai_utils/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (174 Bytes). View file
|
|
utils/openai_utils/__pycache__/chatmodel.cpython-311.pyc
ADDED
Binary file (1.67 kB). View file
|
|
utils/openai_utils/__pycache__/embedding.cpython-311.pyc
ADDED
Binary file (3.38 kB). View file
|
|
utils/openai_utils/__pycache__/prompts.cpython-311.pyc
ADDED
Binary file (5.42 kB). View file
|
|
utils/openai_utils/chatmodel.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import os
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
|
8 |
+
class ChatOpenAI:
|
9 |
+
def __init__(self, model_name: str = "gpt-3.5-turbo"):
|
10 |
+
self.model_name = model_name
|
11 |
+
self.openai_api_key = os.getenv("OPENAI_API_KEY")
|
12 |
+
if self.openai_api_key is None:
|
13 |
+
raise ValueError("OPENAI_API_KEY is not set")
|
14 |
+
|
15 |
+
def run(self, messages, text_only: bool = True):
|
16 |
+
if not isinstance(messages, list):
|
17 |
+
raise ValueError("messages must be a list")
|
18 |
+
|
19 |
+
openai.api_key = self.openai_api_key
|
20 |
+
response = openai.ChatCompletion.create(
|
21 |
+
model=self.model_name, messages=messages
|
22 |
+
)
|
23 |
+
|
24 |
+
if text_only:
|
25 |
+
return response.choices[0].message.content
|
26 |
+
|
27 |
+
return response
|
utils/openai_utils/embedding.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
from openai.embeddings_utils import (
|
3 |
+
get_embeddings,
|
4 |
+
aget_embeddings,
|
5 |
+
get_embedding,
|
6 |
+
aget_embedding,
|
7 |
+
)
|
8 |
+
import openai
|
9 |
+
from typing import List
|
10 |
+
import os
|
11 |
+
import asyncio
|
12 |
+
|
13 |
+
|
14 |
+
class EmbeddingModel:
|
15 |
+
def __init__(self, embeddings_model_name: str = "text-embedding-ada-002"):
|
16 |
+
load_dotenv()
|
17 |
+
self.openai_api_key = os.getenv("OPENAI_API_KEY")
|
18 |
+
|
19 |
+
if self.openai_api_key is None:
|
20 |
+
raise ValueError(
|
21 |
+
"OPENAI_API_KEY environment variable is not set. Please set it to your OpenAI API key."
|
22 |
+
)
|
23 |
+
openai.api_key = self.openai_api_key
|
24 |
+
self.embeddings_model_name = embeddings_model_name
|
25 |
+
|
26 |
+
async def async_get_embeddings(self, list_of_text: List[str]) -> List[List[float]]:
|
27 |
+
return await aget_embeddings(
|
28 |
+
list_of_text=list_of_text, engine=self.embeddings_model_name
|
29 |
+
)
|
30 |
+
|
31 |
+
async def async_get_embedding(self, text: str) -> List[float]:
|
32 |
+
return await aget_embedding(text=text, engine=self.embeddings_model_name)
|
33 |
+
|
34 |
+
def get_embeddings(self, list_of_text: List[str]) -> List[List[float]]:
|
35 |
+
return get_embeddings(
|
36 |
+
list_of_text=list_of_text, engine=self.embeddings_model_name
|
37 |
+
)
|
38 |
+
|
39 |
+
def get_embedding(self, text: str) -> List[float]:
|
40 |
+
return get_embedding(text=text, engine=self.embeddings_model_name)
|
41 |
+
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
embedding_model = EmbeddingModel()
|
45 |
+
print(embedding_model.get_embedding("Hello, world!"))
|
46 |
+
print(embedding_model.get_embeddings(["Hello, world!", "Goodbye, world!"]))
|
47 |
+
print(asyncio.run(embedding_model.async_get_embedding("Hello, world!")))
|
48 |
+
print(
|
49 |
+
asyncio.run(
|
50 |
+
embedding_model.async_get_embeddings(["Hello, world!", "Goodbye, world!"])
|
51 |
+
)
|
52 |
+
)
|
utils/openai_utils/prompts.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
+
|
4 |
+
class BasePrompt:
|
5 |
+
def __init__(self, prompt):
|
6 |
+
"""
|
7 |
+
Initializes the BasePrompt object with a prompt template.
|
8 |
+
|
9 |
+
:param prompt: A string that can contain placeholders within curly braces
|
10 |
+
"""
|
11 |
+
self.prompt = prompt
|
12 |
+
self._pattern = re.compile(r"\{([^}]+)\}")
|
13 |
+
|
14 |
+
def format_prompt(self, **kwargs):
|
15 |
+
"""
|
16 |
+
Formats the prompt string using the keyword arguments provided.
|
17 |
+
|
18 |
+
:param kwargs: The values to substitute into the prompt string
|
19 |
+
:return: The formatted prompt string
|
20 |
+
"""
|
21 |
+
matches = self._pattern.findall(self.prompt)
|
22 |
+
return self.prompt.format(**{match: kwargs.get(match, "") for match in matches})
|
23 |
+
|
24 |
+
def get_input_variables(self):
|
25 |
+
"""
|
26 |
+
Gets the list of input variable names from the prompt string.
|
27 |
+
|
28 |
+
:return: List of input variable names
|
29 |
+
"""
|
30 |
+
return self._pattern.findall(self.prompt)
|
31 |
+
|
32 |
+
|
33 |
+
class RolePrompt(BasePrompt):
|
34 |
+
def __init__(self, prompt, role: str):
|
35 |
+
"""
|
36 |
+
Initializes the RolePrompt object with a prompt template and a role.
|
37 |
+
|
38 |
+
:param prompt: A string that can contain placeholders within curly braces
|
39 |
+
:param role: The role for the message ('system', 'user', or 'assistant')
|
40 |
+
"""
|
41 |
+
super().__init__(prompt)
|
42 |
+
self.role = role
|
43 |
+
|
44 |
+
def create_message(self, **kwargs):
|
45 |
+
"""
|
46 |
+
Creates a message dictionary with a role and a formatted message.
|
47 |
+
|
48 |
+
:param kwargs: The values to substitute into the prompt string
|
49 |
+
:return: Dictionary containing the role and the formatted message
|
50 |
+
"""
|
51 |
+
return {"role": self.role, "content": self.format_prompt(**kwargs)}
|
52 |
+
|
53 |
+
|
54 |
+
class SystemRolePrompt(RolePrompt):
|
55 |
+
def __init__(self, prompt: str):
|
56 |
+
super().__init__(prompt, "system")
|
57 |
+
|
58 |
+
|
59 |
+
class UserRolePrompt(RolePrompt):
|
60 |
+
def __init__(self, prompt: str):
|
61 |
+
super().__init__(prompt, "user")
|
62 |
+
|
63 |
+
|
64 |
+
class AssistantRolePrompt(RolePrompt):
|
65 |
+
def __init__(self, prompt: str):
|
66 |
+
super().__init__(prompt, "assistant")
|
67 |
+
|
68 |
+
|
69 |
+
if __name__ == "__main__":
|
70 |
+
prompt = BasePrompt("Hello {name}, you are {age} years old")
|
71 |
+
print(prompt.format_prompt(name="John", age=30))
|
72 |
+
|
73 |
+
prompt = SystemRolePrompt("Hello {name}, you are {age} years old")
|
74 |
+
print(prompt.create_message(name="John", age=30))
|
75 |
+
print(prompt.get_input_variables())
|
utils/text_utils.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
|
5 |
+
class TextFileLoader:
|
6 |
+
def __init__(self, path: str, encoding: str = "utf-8"):
|
7 |
+
self.documents = []
|
8 |
+
self.path = path
|
9 |
+
self.encoding = encoding
|
10 |
+
|
11 |
+
def load(self):
|
12 |
+
if os.path.isdir(self.path):
|
13 |
+
self.load_directory()
|
14 |
+
elif os.path.isfile(self.path) and self.path.endswith(".txt"):
|
15 |
+
self.load_file()
|
16 |
+
else:
|
17 |
+
raise ValueError(
|
18 |
+
"Provided path is neither a valid directory nor a .txt file."
|
19 |
+
)
|
20 |
+
|
21 |
+
def load_file(self):
|
22 |
+
with open(self.path, "r", encoding=self.encoding) as f:
|
23 |
+
self.documents.append(f.read())
|
24 |
+
|
25 |
+
def load_directory(self):
|
26 |
+
for root, _, files in os.walk(self.path):
|
27 |
+
for file in files:
|
28 |
+
if file.endswith(".txt"):
|
29 |
+
with open(
|
30 |
+
os.path.join(root, file), "r", encoding=self.encoding
|
31 |
+
) as f:
|
32 |
+
self.documents.append(f.read())
|
33 |
+
|
34 |
+
def load_documents(self):
|
35 |
+
self.load()
|
36 |
+
return self.documents
|
37 |
+
|
38 |
+
|
39 |
+
class CharacterTextSplitter:
|
40 |
+
def __init__(
|
41 |
+
self,
|
42 |
+
chunk_size: int = 1000,
|
43 |
+
chunk_overlap: int = 200,
|
44 |
+
):
|
45 |
+
assert (
|
46 |
+
chunk_size > chunk_overlap
|
47 |
+
), "Chunk size must be greater than chunk overlap"
|
48 |
+
|
49 |
+
self.chunk_size = chunk_size
|
50 |
+
self.chunk_overlap = chunk_overlap
|
51 |
+
|
52 |
+
def split(self, text: str) -> List[str]:
|
53 |
+
chunks = []
|
54 |
+
for i in range(0, len(text), self.chunk_size - self.chunk_overlap):
|
55 |
+
chunks.append(text[i : i + self.chunk_size])
|
56 |
+
return chunks
|
57 |
+
|
58 |
+
def split_texts(self, texts: List[str]) -> List[str]:
|
59 |
+
chunks = []
|
60 |
+
for text in texts:
|
61 |
+
chunks.extend(self.split(text))
|
62 |
+
return chunks
|
63 |
+
|
64 |
+
|
65 |
+
if __name__ == "__main__":
|
66 |
+
loader = TextFileLoader("data/KingLear.txt")
|
67 |
+
loader.load()
|
68 |
+
splitter = CharacterTextSplitter()
|
69 |
+
chunks = splitter.split_texts(loader.documents)
|
70 |
+
print(len(chunks))
|
71 |
+
print(chunks[0])
|
72 |
+
print("--------")
|
73 |
+
print(chunks[1])
|
74 |
+
print("--------")
|
75 |
+
print(chunks[-2])
|
76 |
+
print("--------")
|
77 |
+
print(chunks[-1])
|
utils/vectordatabase.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from collections import defaultdict
|
3 |
+
from typing import List, Tuple, Callable
|
4 |
+
from utils.openai_utils.embedding import EmbeddingModel
|
5 |
+
import asyncio
|
6 |
+
|
7 |
+
|
8 |
+
def cosine_similarity(vector_a: np.array, vector_b: np.array) -> float:
|
9 |
+
"""Computes the cosine similarity between two vectors."""
|
10 |
+
dot_product = np.dot(vector_a, vector_b)
|
11 |
+
norm_a = np.linalg.norm(vector_a)
|
12 |
+
norm_b = np.linalg.norm(vector_b)
|
13 |
+
return dot_product / (norm_a * norm_b)
|
14 |
+
|
15 |
+
|
16 |
+
class VectorDatabase:
|
17 |
+
def __init__(self, embedding_model: EmbeddingModel = None):
|
18 |
+
self.vectors = defaultdict(np.array)
|
19 |
+
self.embedding_model = embedding_model or EmbeddingModel()
|
20 |
+
|
21 |
+
def insert(self, key: str, vector: np.array) -> None:
|
22 |
+
self.vectors[key] = vector
|
23 |
+
|
24 |
+
def search(
|
25 |
+
self,
|
26 |
+
query_vector: np.array,
|
27 |
+
k: int,
|
28 |
+
distance_measure: Callable = cosine_similarity,
|
29 |
+
) -> List[Tuple[str, float]]:
|
30 |
+
scores = [
|
31 |
+
(key, distance_measure(query_vector, vector))
|
32 |
+
for key, vector in self.vectors.items()
|
33 |
+
]
|
34 |
+
return sorted(scores, key=lambda x: x[1], reverse=True)[:k]
|
35 |
+
|
36 |
+
def search_by_text(
|
37 |
+
self,
|
38 |
+
query_text: str,
|
39 |
+
k: int,
|
40 |
+
distance_measure: Callable = cosine_similarity,
|
41 |
+
return_as_text: bool = False,
|
42 |
+
) -> List[Tuple[str, float]]:
|
43 |
+
query_vector = self.embedding_model.get_embedding(query_text)
|
44 |
+
results = self.search(query_vector, k, distance_measure)
|
45 |
+
return [result[0] for result in results] if return_as_text else results
|
46 |
+
|
47 |
+
def retrieve_from_key(self, key: str) -> np.array:
|
48 |
+
return self.vectors.get(key, None)
|
49 |
+
|
50 |
+
async def abuild_from_list(self, list_of_text: List[str]) -> "VectorDatabase":
|
51 |
+
embeddings = await self.embedding_model.async_get_embeddings(list_of_text)
|
52 |
+
for text, embedding in zip(list_of_text, embeddings):
|
53 |
+
self.insert(text, np.array(embedding))
|
54 |
+
return self
|
55 |
+
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
list_of_text = [
|
59 |
+
"I like to eat broccoli and bananas.",
|
60 |
+
"I ate a banana and spinach smoothie for breakfast.",
|
61 |
+
"Chinchillas and kittens are cute.",
|
62 |
+
"My sister adopted a kitten yesterday.",
|
63 |
+
"Look at this cute hamster munching on a piece of broccoli.",
|
64 |
+
]
|
65 |
+
|
66 |
+
vector_db = VectorDatabase()
|
67 |
+
vector_db = asyncio.run(vector_db.abuild_from_list(list_of_text))
|
68 |
+
k = 2
|
69 |
+
|
70 |
+
searched_vector = vector_db.search_by_text("I think fruit is awesome!", k=k)
|
71 |
+
print(f"Closest {k} vector(s):", searched_vector)
|
72 |
+
|
73 |
+
retrieved_vector = vector_db.retrieve_from_key(
|
74 |
+
"I like to eat broccoli and bananas."
|
75 |
+
)
|
76 |
+
print("Retrieved vector:", retrieved_vector)
|
77 |
+
|
78 |
+
relevant_texts = vector_db.search_by_text(
|
79 |
+
"I think fruit is awesome!", k=k, return_as_text=True
|
80 |
+
)
|
81 |
+
print(f"Closest {k} text(s):", relevant_texts)
|